Relative Content

Tag Archive for javascriptreactjsreact-hooks

React state is not updating 2d array

I’m building a React application that asks the user for an input, and if correct (enter “3”), we render a 10×10 grid of buttons, each tied to a click handler.

useEffect() with empty dependency array not running on page refresh

I am trying to do some session verification when my page is initially loaded. The AuthenticationRequiredComponent is used as a wrapper for other components that require authentication. If users are not logged in, they should be redirected to the login page. This component has a useEffect callback defined with an empty dependency array, because it subscribes to an auth state change (it is using Firebase Auth). If I go through the whole process of logging in to my website, and get to a page that uses this wrapper, the useEffect is called correctly. However, if I am in a page that uses this wrapper and I hit refresh or if I navigate directly to the url of a page that uses this wrapper, the useEffect is not being called, which results in the page not working correctly. The project is fairly large, so I cannot post the entire code. I will add pseudocode of some of the parent elements for structure:

useEffect() with empty dependency array not running on page refresh

I am trying to do some session verification when my page is initially loaded. The AuthenticationRequiredComponent is used as a wrapper for other components that require authentication. If users are not logged in, they should be redirected to the login page. This component has a useEffect callback defined with an empty dependency array, because it subscribes to an auth state change (it is using Firebase Auth). If I go through the whole process of logging in to my website, and get to a page that uses this wrapper, the useEffect is called correctly. However, if I am in a page that uses this wrapper and I hit refresh or if I navigate directly to the url of a page that uses this wrapper, the useEffect is not being called, which results in the page not working correctly. The project is fairly large, so I cannot post the entire code. I will add pseudocode of some of the parent elements for structure: