Example 5 — RTK Query
createApi + fetchBaseQuery: login mutation stores token in a small session slice; getMe query runs with the Bearer header. Compare with Example 4 manual thunk.
RTK Query owns request lifecycle, cache, and hooks. Use thunks when you need custom imperative flows; use RTK Query for server data sync.
Files to read
Open these in the repo — each example is isolated in its own folder.
- src/app/learn/redux/example-5-rtk-query/NOTES.md
- src/app/learn/redux/example-5-rtk-query/_features/authApi.ts
- src/app/learn/redux/example-5-rtk-query/_components/RtkQueryDemo.tsx