Example 4 — Login flow
Interview classic: when the user clicks Login, the form dispatches the login async thunk. Pending shows loading; fulfilled stores user + token; rejected shows API error. Components subscribed to state.auth re-render at each step.
text
User clicks Login
→ dispatch(login({ email, password }))
→ pending: status = loading
→ POST /learn/redux/api/mock-auth
→ fulfilled: user + token in store | rejected: error messageFiles to read
Open these in the repo — each example is isolated in its own folder.
- src/app/learn/redux/example-4-login/NOTES.md
- src/app/learn/redux/api/mock-auth/route.ts
- src/app/learn/redux/example-4-login/_features/authSlice.ts
- src/app/learn/redux/example-4-login/_components/LoginDemo.tsx