I have a react app that is mapping products that i have fetched . However i want the random products to be only 5 and not many.
Here is my code
const Section13: React.FC = () => {
const [visibleSlides, setVisibleSlides] = useState(6);
const width = useWindowSize();
const [productsList, setproductsList] = useState([]);
useEffect(() => {
if (width < 370) setVisibleSlides(1);
else if (width < 650) setVisibleSlides(2);
else if (width < 950) setVisibleSlides(4);
else setVisibleSlides(6);
// get products from DB
var config: AxiosRequestConfig = {
method: "get",
url: "https://backendkwingy.online/api/products",
headers: {},
};
axios(config)
.then(function (response) {
setproductsList(response.data.allProducts);
})
.catch(function (error) {
console.log(error);
});
}, [width]);
const productsLists = productsList.sort(
() => Math.random() - Math.random()
);
what m mappping is productsList so is there a way i can make the ranom code randomize only 5 products than many