Тёмный

STOP using Redux! Start using React Hooks UseContext instead 

Tigran Tech
Подписаться 838
Просмотров 8 тыс.
50% 1

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

Опубликовано:

 

8 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 18   
@tigrantech
@tigrantech 4 года назад
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?
@coldcerberus9425
@coldcerberus9425 3 года назад
Hi @Tigran, I'm looking on how we justify this with an example on actual API calls. What do you think of this article, "React Hooks + RxJS or How React Is Meant to Be", by Kirill Novik? Would it be a good idea to implement some kind of an equivalent of the Angular Providers (for API calling services), probably using axios-observable, and use it along with the custom hook in the article?
2 года назад
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.
@joaolavoier6960
@joaolavoier6960 4 года назад
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"?
@KarolCud
@KarolCud 3 года назад
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? :)
@At3nT
@At3nT Год назад
I think you solve that with useMemo and useCallback
@KarolCud
@KarolCud Год назад
@@At3nT I think, that it isn't good solution. Using UseMemo/Callback will only "simulate" correct action. By the way, my comment has 2 years. Now ContextApi working correctly (with re-renders) from the box :)
@muzaradi
@muzaradi 2 года назад
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.
@At3nT
@At3nT Год назад
I think you solve that with useMemo and useCallback
@aarondz789
@aarondz789 4 года назад
Maybe your code is too simple.
@djamaatul
@djamaatul 2 года назад
i learn recrt this year, and prever context than redux
@sagarjaid
@sagarjaid 2 года назад
😂
@thepickicool97
@thepickicool97 4 года назад
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.
@glepard7640
@glepard7640 4 года назад
I work as a front-end developer in a start up, with a web app made in react, wich is 10k+ lines, using server side rendering, and it doesn't have a single class component. So no, redux and class componets aren't 'absolutly necessary'
@thepickicool97
@thepickicool97 4 года назад
@@glepard7640 I'm curious about how you manage user authentication ! It would be really interesting !
@glepard7640
@glepard7640 4 года назад
@@thepickicool97 On the front-end? I just store the token on the browser cookies...
@webdev1652
@webdev1652 3 года назад
Thats the reason why theres a functional way of doing it in react. And thats more efficient
Далее
Why I Love useReducer
22:40
Просмотров 92 тыс.
Why React Hooks?
14:04
Просмотров 174 тыс.
Мама знает где все документы
00:21
Men Vs Women Survive The Wilderness For $500,000
31:48
ВОТ ЧТО МЫ КУПИЛИ НА ALIEXPRESS
11:28
CALM #162 - Circuit Python my love 💕
44:07
React Context vs Redux - Who wins?
31:32
Просмотров 233 тыс.
Learn React Hooks: useContext - Simply Explained!
15:46
Context API in react | get the concept
29:00
Просмотров 55 тыс.
React Hooks useContext Tutorial (Storing a User)
11:38
Просмотров 358 тыс.
State Managers Are Making Your Code Worse In React
13:33
React Hooks: Advanced Hooks
20:52
Просмотров 87 тыс.
Context API Tutorial For Beginners - Using React Hooks
12:26
Мама знает где все документы
00:21