You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+73Lines changed: 73 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -359,6 +359,7 @@ You can download the PDF and Epub version of this repository from the latest run
359
359
|322|[What is the purpose of eslint plugin for hooks?](#what-is-the-purpose-of-eslint-plugin-for-hooks)|
360
360
|323|[What is the difference between Imperative and Declarative in React?](#what-is-the-difference-between-imperative-and-declarative-in-react)|
361
361
|324|[What are the benefits of using typescript with reactjs?](#what-are-the-benefits-of-using-typescript-with-reactjs)|
362
+
|325|[How do you make sure that user remains authenticated on page refresh while using Context API State Management?](#how-do-you-make-sure-that-user-remains-authenticated-on-page-refresh-while-using-Context-API-State-Management?)|
362
363
363
364
## Core React
364
365
@@ -6551,3 +6552,75 @@ You can download the PDF and Epub version of this repository from the latest run
6551
6552
2. Use of interfaces for complex type definitions
6552
6553
3. IDEs such as VS Code was made for TypeScript
6553
6554
4. Avoid bugs with the ease of readability and Validation
6555
+
6556
+
**[⬆ Back to Top](#table-of-contents)**
6557
+
6558
+
325. ### How do you make sure that user remains authenticated on page refresh while using Context API State Management?
6559
+
When a user logs in and reload, to persist the state generally we add the load user action in the useEffect hooks in the main App.js. While using Redux, loadUser action can be easily accessed.
6560
+
6561
+
**App.js**
6562
+
6563
+
```js
6564
+
import {lodUser} from'../actions/auth';
6565
+
store.dispatch(loadUser());
6566
+
```
6567
+
6568
+
* But while using **Context API**, to access context in App.js, wrap the AuthState in index.js so that App.js can access the auth context. Now whenever the page reloads, no matter what route you are on, the user will be authenticated as **loadUser** action will be triggered on each re-render.
0 commit comments