Currently, I want to forceUpdate function component, I work around and find one way
function useForceUpdate() {
const [, setValue] = useState(0); // integer state
return () => setValue(value => value + 1); // update the state to force render
}
const forceUpdate = useForceUpdate();
and I use it inside useEffect() hook
useEffect(() => {
forceUpdate();
})
But It cause Warning: Maximum update depth exceeded. and rerender componenet many times. And then I try
useEffect(() => {
const timeout = setTimeout(() => {
forceUpdate()
}, 0)
return () => {
clearTimeout(timeout);
}
})
It solved for warning Maximum update depth exceeded.