I have a pure functional component where I fetch some data using useEffect. I pass in an empty string to useEffect, so it acts like a component did mount.
const getData = () => {
setTimeout(() => {
setLocalState({ a: 2 });
setIsLoading(false);
}, 0);
};
useEffect(() => getData(), []);
My entire component re-renders twice right now. I want to control this behavior and only re-render with certain conditions.
Here, I want the component to reRender when setLocalState has set the localState but not when setIsLoading has set isLoading to false.
Here's a code sandbox for this problem: https://codesandbox.io/s/0oyp6j506p