DEV Community

Discussion on: How to add Redux Toolkit to a React-Redux application ⚛️

Collapse
 
phryneas profile image
Lenz Weber

Just two nitpicks there :)

  • it's slice, not slicer - although a lot of people seem to call it that 😅
  • nowadays we recommend to use the react-redux hooks useSelector and useDispatch. connect is pretty much a legacy api.
Collapse
 
maxinejs profile image
Maxine

Thank you so much for the feedback! I have seen them called slices and slicers, (I just went with slicers for personal preference), but good to know! And I also didn't know connect was considered a "legacy" API, so I will have to refresh my knowledge on useSelector/Dispatch. But, again thank you!

Collapse
 
lexiebkm profile image
Alexander B.K.

Connect is a legacy API ? Then, how we can use React-Redux when we still have to work with class components ? Connect is still provided for working with class components.

Collapse
 
phryneas profile image
Lenz Weber • Edited

It is there and it will not go away in the next version of React-Redux. But due to declining ecosystem support for class components of essentially all new libraries (and forseeable limited usability in React 18), class components themselves are essentially a legacy api.

I would not recommend anyone to write new class components at this point and so I would also not recommend anyone to write a new usage of connect, since in function components hooks are a lot easier to reason about for most people.

Thread Thread
 
lexiebkm profile image
Alexander B.K.

Sure, as React team also encourage us to use Hooks in new projects; hence we can also use Hooks API of React-Redux, instead of Connect. But, like I said, in case of existing codebases that still use class components, we still have to use Connect API.
I myself, by the suggestion of React team, will start to use Hooks in new projects, from which I can use Hooks API from React-Redux.
I am also now considering to use useReducer in combination with Context as an alternative to Redux, as mentioned in the following article : dev.to/kendalmintcode/replacing-re...
I will try this approach, although I am not sure if it will fit to my need.

Thread Thread
 
phryneas profile image
Lenz Weber

I said multiple times, we are not going to remove it and using it is safe. We still consider it "legacy" in the sense that most users will probably never connect a new component again and over a longer time it's usage might fade away. We will keep it running but will probably never add any new feature to it.

As for context for state, I would advise against that: Context is a dependency injection mechanism meant for seldomly changing values - it is not meant for something like state (we tried that in react-redux 6 and performance was very bad) that might change a lot, especially since it does not support partial subscriptions. Give dev.to/javmurillo/react-context-al... a read.

Thread Thread
 
lexiebkm profile image
Alexander B.K. • Edited

Thanks for telling me about caveats of Context for using it as global state management. That is actually I have been wondering so far.
Now that I have found that you are an expert, who is a contributor of Redux Toolkit, I should take your advice.
I am still learning Redux with RTK, including RTK query as well as React-Redux. There are a lot of things to learn of these Redux technology that need time/patience to use it correctly, but I hope it will pay of in the long run for me.

Thread Thread
 
maxinejs profile image
Maxine

Thanks again for the awesome info! @phryneas

Thread Thread
 
maxinejs profile image
Maxine

I have dropped my use of connect since your initial comment, and it has made my life easier no doubt!