Relative Content

Tag Archive for javascriptreactjsreact-hooksreact-contextcreatecontext

Problems using a useState to modify a context

I am following a course to learn how to implement a login system. While creating the AuthProvider to test the context functionality, I changed the default value of isAuthenticated in the useState to “true”. However, when using it in the ProtectedRoute, it returns the value set in the createContext and does not allow me to access the protected routes. If I change the value in the createContext to “true”, it works, as if it is ignoring the useState.