I use setInterval in my code to make my slider work. It should change image each 5 second . But I see that when I use it , it consume new memory all the time . How can I use setInterval without consuming new memory ?
const Slider = ({ children, sliderIndex, setSlideIndex }) => {
const classes = useStyles()
useInterval(() => {
setSlideIndex((sliderIndex + 1) % children.length)
}, 5000)
const animateFunc = useCallback(
(child, indx) => {
return (
(indx === sliderIndex && (
<div className={classes.root} key={indx}>
{children[sliderIndex].image}
</div>
)) ||
null
)
},
[children, classes.root, sliderIndex]
)
return children.map(animateFunc)
}
i use @use-it/interval hook for it https://www.npmjs.com/package/@use-it/interval

children.map(animateFunc)is NOT how you map children in React (see React docs Children API). You should add codesandbox for more help...