React - The Complete Guide

Section 18: Understanding Redux - Managing App - Wide State with Redux

olivia_yj 2023. 2. 9. 02:36

The goals

💪🏻What is Redux? 

✌🏻Redux Baisics & Using Redux with React

👍🏻Redux Toolkit

 

When we use the reducer function for the first time, since it doesn't know the initial state, it can't read the state and occur some errors.

So we should give the initial value to the state when we use the reducer function for the first time.

So if we set the value and run the code, then we can see it works well.

Because we set the initial value 'state = { counter: 0 }'

We dispatched the action with its own name

We can use if statement here and add another action

We should never mutate the state like this. We should remember that it always overrides the past state.

Redux-tookit makes dispatching action much easier. 

 


We can use 'useSelector' from redux to show our header menu for only some specific situation like logged in (authenticated)