State Management in ReactJS

**Managing State with useState**

React’s useState() hook is used to store dynamic values—anything that changes while the app runs.

In the carousel, we use two key state variables:

const [uploadedImages, setUploadedImages] = useState([]);
const [currentIndex, setCurrentIndex] = useState(0);
  • uploadedImages stores the list of images that users upload.
  • currentIndex stores the index of the currently displayed image.

When no images are uploaded, we fall back to showing the default images:

const images = uploadedImages.length > 0 ? uploadedImages : defaultImages;

This logic ensures that the carousel always has something to display.