0

If I remove the dependencies array at the end then the component goes on a loop that keeps fetching data. If I add the 'isError' and 'isLoading' inside the array then the error disappears but I still go on a loop. Why is this happening in the 'isError' and 'isLoading' and not in the 'data'?

enter image description here

export default function App() { const [data, setData] = useState({}); const [isError, setIsError] = useState(false); const [isLoading, setIsLoading] = useState(false); useEffect(() => { const fetchData = async () => { try { setIsError(false); setIsLoading(true); console.log('[isLoading]: ' + isLoading); const response = await axios( 'http://localhost:4000/website', ); setData(response.data); setIsLoading(false); } catch (error) { setIsError(true); console.log('[error]: ' + isError); } }; fetchData().then(r => console.log('[### fetchData]: Successful')); }, []); console.log(data); return ( <Provider store={store}> <Router> {isLoading ? ( <div>Loading ...</div> ) : ( <div className="App"> <Navbar /> <Route exact path="/" component={Landing} /> <Route exact path="/register" component={Register} /> <Route exact path="/login" component={Login} /> <Switch> <PrivateRoute exact path="/dashboard" component={Dashboard} /> </Switch> </div> )} </Router> </Provider> ); } 
3
  • 2
    Just remove the two console.log() commands. Commented May 18, 2020 at 7:54
  • Or ignore the warning while you have them. Commented May 18, 2020 at 7:58
  • @ChrisG this is it. If you write an answer I will mark it as solved. Commented May 18, 2020 at 8:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.