0
votes

I have created a login component, and there is a state Auth with redux

that and reducer to update the Auth state (initally it is set as FALSE)

but on initial render dispatch is called 4 times and state is updated to TRUE

i have tried useMemo, but not sure how exacltly use it.

https://codesandbox.io/s/react-reducer-ijhj5?file=/src/Components/LoginComponent.js

1

1 Answers

1
votes

Your code has a bug

<button onClick={() => memoziedLogin}>Login</button>

The memoziedLogin should be called like memoziedLogin(). See below bellow

<button onClick={() => memoziedLogin()}>Login</button>