skip to Main Content

Javascript – React: setState inside a promise does not change the state value

I have the following code: function App() { const [appData, setAppData] = useState(initialAppDataValue); const [test, setTest] = useState(""); // outside useEffect if(!DataProviderService.isInitialized){ fetchData(); } // inside useEffect /*useEffect(() => { fetchData(); }, []);*/ function fetchData(){ DataProviderService.getAppData().then((data) => { setAppData(data); setTest("abc");…

VIEW QUESTION
Back To Top
Search