Someone just pointed me to the Next.js "with Redux Toolkit" example...
and I& #39;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">https://github.com/zeit/next... someone please file a PR to clean up that example and do things the _right_ way?
and I& #39;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">https://github.com/zeit/next... 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
- 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& #39;t be using `createAction/createReducer` anyway. `createSlice` does that for you!
- Small counter example, but reducer logic shouldn& #39;t live in `store.js`. Split that into a features/slice file.
- Small counter example, but reducer logic shouldn& #39;t live in `store.js`. Split that into a features/slice file.
Finally, abstracting Redux logic into custom React hooks is not something I& #39;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.
Basically, someone take our Redux template for CRA (which uses Redux Toolkit), and adapt it to Next.js, please: https://github.com/reduxjs/cra-template-redux">https://github.com/reduxjs/c...