STOP using Redux! Start using React Hooks UseContext instead

preview_player
Показать описание
At the first steps of getting into React-based UI applications, I kinda hated Redux stuff, because you really not getting enough benefits of having that's a match of a complexity and file structure inside an application, and also it comes out with a huge dependency, which is not required to have!

React Hooks actually replaced most of the stuff that you have to have when making an extensive React application. Same with Redux stuff, using React Hooks UseContext you can actually replace the entire Redux workflow, and not even think to have a dependency on that.

There is a lot more than you can use with React Hooks, for example, Apollo GraphQL client comes with defined hooks, which makes a lot more easier to connect to components and not worry about keeping API data somewhere available, it will be there anyway because it just keeps a cache of that.

#react #hooks #redux
Рекомендации по теме
Комментарии
Автор

I spent about a day refactoring my previous app by removing Redux completely. Curious if anybody did similar thing? and how match time it is actually taking for other cases?

tigrantech
Автор

I understand your point of view. But about the performance features and the side-effect management? If I have to implement everything, don't you think that it could be a "reinventing the wheel"?

joaolavoier
Автор

Everything ok, BUT your component will always re-render when one of context' property change. Even if you want use only single prop. So if your app is small and store hasn't many props is good to use context but in more complicated apps better approach is to use mobx or redux. Am I wrong? :)

KarolCud
Автор

I would have loved to see how this example looks in react too, so that I could decide which syntax looks better for me. A lot of reasons you mentioned against redux are subjective: "easy to misconfigure", "more difficult", "adds a lot of complexity to your code". For me the only valid argument you mentioned in the whole video is that useContext comes out of the box with react, while redux is a separate dependency. Also, I feel you are comparing apples to oranges, the true counterpart or replacement for redux would be the useReducer, which you don't mention in this video. Having to build the functionality of redux using useContext and useReducer feels like assembling low level stuff to something, which works out of the box with redux. Finally, there are other options to ease development with redux, as a starter I would recommend Eric Elliot's autodux, which does a good job in reducing the boilerplate code necessary for redux. Would have been nice to actually see your refactoring in a diff view to see how the 100s of lines of codes were reduced to 10s of lines of code.

Автор

This is not alternative of Redux. In large applications it causes performance problems. We should only use contexts when we need to access data in many components, which are at different nesting levels. Furthermore, we need to make sure that we only use contexts for non-frequently changing data. Frequently changing values of contexts can cause our whole component tree to re-render, resulting in performance problems. That is why, for frequently changing values, we should use a state management solution such as Redux or MobX, instead.

muzaradi
Автор

i learn recrt this year, and prever context than redux

djamaatul
Автор

How to use a Hook in a class Component... ? You don't know ? Exactly, because it's impossible.
For everybody wondering... today, on May 2020, you can manage state with Hooks only in small application (or on a small component scale).
But if you want to manage the user state with hooks.... soon or later, you will face some problems.
Especially in the server-side rendering world where class component are absolutely necessary.

thepickicool
join shbcf.ru