score:0

since fetch api and setstate are both asynchronous, you might want to put the if statement and all logic inside .then(…)

fetch(…)
 .then(res => res.json())
 .then(json => … //navigate here)
 .catch(err => … //set your error state here)


Related Query

More Query from same tag