I said this in another comment, but similarly to this, check out Redux Toolkit (https://redux-toolkit.js.org), the `slices` feature changed my view on Redux entirely. Basically you can have a per-feature slice of functionality rather than having actions, reducers, and constants spread around your code. It's analogous to what hooks did, encapsulating similar functionality.
RTK is great! The only thing I wish was a bit different is the `createAsyncThunk` function. It feels dirty providing the action-type string manually, when for all the other actions, this is essentially invisible.
The idea of having some kind of special syntax in `createSlice` to support declaring thunks has definitely been suggested, and there's other libraries out there that do similar things. But, anything we add to our API has to be supported indefinitely. Because of that, I wanted to release `createAsyncThunk` and `createEntityAdapter` as "standalone" utilities first and see how they actually get used by the community.
I'm definitely open to potentially integrating them together down the road, but I'd rather take it one step at a time and make sure that we're really solving the right problems the right way.
If you do have any further feedback on RTK, please feel free to file issues for discussion!
This is similar to how I've always implemented Redux before using some of my own utilities, but it's nice they have an "official" way to do it now. Does it work well with TypeScript?
Yep, RTK is specifically written in TypeScript, and I have a co-maintainer (Lenz Weber) who has done an amazing job working on the TS typedefs to make sure it works well.
I'm a Redux maintainer. As I said over on Reddit when this was posted:
The biggest issue is that it goes directly against the principles I listed in the Redux Style Guide [0], particularly:
- put as much logic as possible in reducers [1]
- reducers should own the state shape [2]
- model actions as "events", not "setters" [3]
Also, Dan pointed out early on in Redux's development that "cursor"-style approaches to state updates are not how he intended people to use Redux [4].
Will it run? Sure. Is it something I'd actually recommend? Definitely not, and especially given the existence of our official Redux Toolkit package [5] and the React-Redux hooks API [6].
Considering how verbose the current UX of Redux is, this needs to be merged into mainline React. Are there any significant performance overhead? This is a really great library, the ergonomics look amazing and the documentation is just gorgeous.
Check out Redux Toolkit (https://redux-toolkit.js.org), the `slices` feature changed my view on Redux entirely. Basically you can have a per-feature slice of functionality rather than having actions, reducers, and constants spread around your code. It's analogous to what hooks did, encapsulating similar functionality.
Thanks. It uses useDispatch behind the scenes which I believe has a bit more overhead compared to using connect. It should be comparable performance-wise to using the normal react-redux hooks.
It's redux under the hood so with this library you'd be able to use existing redux tooling such as redux dev tools. Usually that's not possible with bespoke state management libraries (although I'm not familiar with Recoil)
Yep, typically you'd do it by persisting the Redux state. redux-persist is a popular library to do that to localstorage and other backends: https://github.com/rt2zz/redux-persist