Hello,
I have a component (which is the index component when the App loads) that fetches data via an API call when it component mounts. Lets say that I navigate from the component to another place in the App and then come back, how to I prevent another API call when the component remounts ?
For Example
const Main = () => {
const [data, setData] = React.useState();
React,useEffect(() => {
fetch(…Get Data from API…)
.then(res => res.json())
.then(data => setData(data))
}, )
}
How do I prevent the useEffect from running again when the component remounts or I navigate back to from another component in the APP?
Ant idea will be appreciated.