Someone just pointed me to the Next.js "with Redux Toolkit" example...

and I'm sorry to say it is _very_ badly written.

This is _not_ how you use `createAction`!
https://github.com/zeit/next.js/blob/b48eb89d08c4ce750d60e0b807a7393dc8f5fca6/examples/with-redux-toolkit/components/counter.js

Can someone please file a PR to clean up that example and do things the _right_ way?
Expanding on this:

- Bizarre use of `createAction()` inline. Should be used outside components/hooks, once, not inside hooks every time they run.
- If using `createReducer`, should pass action creators as computed object keys, not writing action types as keys by hand
- But more importantly, shouldn't be using `createAction/createReducer` anyway. `createSlice` does that for you!
- Small counter example, but reducer logic shouldn't live in `store.js`. Split that into a features/slice file.
Finally, abstracting Redux logic into custom React hooks is not something I'd do in a "how to" example. Totally valid idea, and something you _can_ do with our hooks, but not the staandard approach. Just `useDispatch()` in the component and dispatch actions as needed.
You can follow @acemarke.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: