Consider the following simple React component with an effect that fetches some data and saves it to the component state:
function MyComponent(props) {
const [data, setData] = useState([]);
useEffect(() => {
const fetchData = async () => {
const res = await fetch("data.json");
setData(await res.json());
};
fetchData();
}, []);
return (
<></>
)
}
What is the right way to set this effect to run periodically, say every minute?
Is it as easy as replacing fetchData() with setInterval(fetchData, 60) or are there other React-specific considerations I should be thinking of?