skip to Main Content

Reactjs – react's useState does not sets new state

I have the following frontend: AuthContext.js: const { createContext, useState, useContext } = require("react"); const AuthContext = createContext(); export function useAuth() { return useContext(AuthContext); } export function AuthProvider({ children }) { const [auth, setAuth] = useState(); return ( <AuthContext.Provider value={{…

VIEW QUESTION

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