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)
Source: stackoverflow.com
Related Query
- State not updating in React Fetch function
- Axios not updating state from API in function called on Click, but works on identical function on Component Mount in React
- React hooks: useState, Updater function nested in for loop not updating state
- React State Variables Not Updating in Function
- React setter function not updating state as expected
- React state not updating after fetch .then statement
- React state not updating after function call
- React why the state is not updating when calling a function to initialize it?
- React navigation with hooks and header function - state is not updating
- State not updating when executing onChange function in React
- React input state not updating with update function which sets state
- React does not change state after updating state in usestate hook (in custom function form)
- React state not updating correctly. Increase and decrease function does not work on first click, but works after subsequent clicks
- React - State not updating function is not updating state correctly
- React state not updating in click event with two functions, but updating with one function
- React Hooks, state not updating from fetch within useEffect
- React Hooks State is only updating once Type:error not a function
- Array not updating in React State in a function component with hooks
- React state not updating using immutability helper update function
- State not updating when printing on same function where updating in React Js
- React Hooks: State Is Not Updating in Function
- React state not updating after it returns from function
- State not updating when using React state hook within setInterval
- React setState not updating state
- React Child Component Not Updating After Parent State Change
- React - useState - why setTimeout function does not have latest state value?
- React component not updating when store state has changed
- Why is my react component not updating with state updates?
- Props not updating when redux state change in React Hooks
- React hooks state variable not updating after rerender
More Query from same tag
- Close detail panel and open another on material-table
- Two instance of React caused by injected script
- Ant design Select component OptGroup in options prop
- Read default value of Material-UI toggle into State
- Value is not updating .. its updating but after refreshing the page but not everytime | Reactjs
- Show/Hide a component in React using state
- Getting Error Response using axios on Client Side in React
- Cannot statically analyse 'require(…, …)' in line 16
- Typescript: How to properly combine different types?
- React getting the ID of clicked button
- React Router: What's the purpose of Browser History? Is Browser History mandatory?
- React form submit and "can't perform state update on an unmounted component"?
- React Router redirect on error 404
- How can I keep input values of React Material UI multiple select after refreshing/reloading the page?
- How to fire a click event in a ul, li or div in reactjs
- I'm getting error when manipulating array
- 'this' inside a function of a class component (react)
- Redirect and send data from Node server back to React
- Does React handle keys automatically when using React.Children.map?
- React Router 4: Route a page to 404 page if it doesn't match with my routing URLs
- How set up a Gatsby Cookie consent banner with gatsby-plugin-gdpr-cookies
- How to delete objects from react state hook array with a button click
- position two components as columns
- How to have multiple react-select options
- React, Snapshot Test useParams undefined
- How to manipulate a global state outside of a React component using Recoil?
- What is necessary to fire Tracker's autorun function?
- How to Render Fetched Object Items in React Component
- Next js - disable server side rendering on some pages
- how to filter firestore data on client side in react