Skip to content Skip to sidebar Skip to footer

React Update State Variable With Json Data

App.js: function App() { const [items, setItems] = useState([]); useEffect(() => { const searchDB = () => { fetch('http://127.0.0.1:8443/subColumns/5/?key=fc257

Solution 1:

Since setItems is the asynchronous method, you can't get the updated value immediately after setItems. You should use another useEffect with dependency to see the value.

useEffect(() => {
  console.log(items);
}, [items]);

Post a Comment for "React Update State Variable With Json Data"