Redux or Context in React

  Рет қаралды 100,829

Ben Awad

Ben Awad

Күн бұрын

Пікірлер: 69
@SeanMatheson
@SeanMatheson 5 жыл бұрын
Hi @Ben Awad - author of easy-peasy here. Happy you have found the library useful. This is a really really great video - thanks so much for making it. It's really important that people understand the trade offs between context and solutions like Redux/Mobx/et al. Even though I am the author of easy-peasy I would always recommend people take some time to consider the best solution for their state management use case. Look forward to more videos from you. 👍
@thedeveloper4207
@thedeveloper4207 5 жыл бұрын
Hi.....Even I have used Easy Peasy and really loved it...Thanks man
@engenglish610
@engenglish610 4 жыл бұрын
Thanks @Sean Matheson, we can use a tool to debug "easy-peasy" like redux Dev tools ?
@rahulsriram6295
@rahulsriram6295 4 жыл бұрын
@@engenglish610 You can use the redux Dev tool itself, cz easy-peasy is just an abstraction layer over redux and thunks
@kidobv8468
@kidobv8468 2 жыл бұрын
Thanks!
@t0digital
@t0digital 2 жыл бұрын
Cool demo. Thank you! That answered on my question. Love youtube for this, one query in search and answer in the first video:)
@eleah2665
@eleah2665 5 жыл бұрын
Hello Ben, you keep talking about things I am interested in - state management and minimizing rerenders. Thanks.
@indiejoseph
@indiejoseph 5 жыл бұрын
The Re-render problem isn’t a big deal, you could extract those children as standalone components and pass them a context as props, so that whenever context changes, and their props keep identical, they wouldn’t rerender
@bawad
@bawad 5 жыл бұрын
yeah you can setup things where the rerender isn't a big deal for context, but in some scenarios is simpler to use a state management lib
@sumanth3036
@sumanth3036 5 жыл бұрын
Thanks @Joseph. Hey Ben, can you make a video how to do this?
@wayneswildworld
@wayneswildworld 2 жыл бұрын
@@bawad What font are you using in this video? I want it!!!
@marcusaureliusregulus2833
@marcusaureliusregulus2833 Жыл бұрын
Hi guys. Can you please give your opinions on whether to use redux or context for a cart? App is a order management system where users place orders for multiple products. ( Retailers ordering from distributors )
@marcola4767
@marcola4767 Жыл бұрын
The problem is when you have other states inside children of a context provider, every time the context state changes, everything inside the provider gets re-rendered and the internal states go back to their default value. Let's say you have a state that manages if a kebab menu should be open and the state is set to true as default, every time you update the state provided, assuming this menu state is inside a component that is a child of the provider, it will always be set to true, so, every action you make that changes the provided state will open the menu because it will re-render the entire component tree and set everything to their default values. That applies if you make a [count, setCount] state inside a provider, whenever you update the provided state, the count state will reset.
@codingfun1285
@codingfun1285 5 жыл бұрын
Brilliant, concise, thanks Ben. 👌👌
@fC-dy4xu
@fC-dy4xu 5 жыл бұрын
Had an argument over this, and I didn't know memoize couldn't work. Multiple contexts is what I've been doing lately, and it suffices so far. Good to know there's still a use case for state management libraries, but I hope react can do something to their core library to solve this re render problem so I wouldn't need to bring in a library
@EverAfterBreak2
@EverAfterBreak2 3 жыл бұрын
I know im 1 year late but they already offered a solution, check the useContext docs
@GhumioDeveloper
@GhumioDeveloper 7 ай бұрын
Very informative and helpful
@darudeSandstorm.
@darudeSandstorm. Жыл бұрын
Very well explained 😊
@softmfq
@softmfq 4 жыл бұрын
So we can say Context API is good to static data in to your application but state management libraries you can keep and also update your application state out of box. One comment we can also replace react context API with plan JS object which we can Import it to our application wherever we want
@JonesDTaylor
@JonesDTaylor 5 жыл бұрын
So basically, context API does not have an extension like the reselect library for redux that allows you to compute and re-ender only the state fields that changed (aka memoized selectors).
@bawad
@bawad 5 жыл бұрын
Yeah
@paulocbbf
@paulocbbf 4 жыл бұрын
Younes Your question cleared my doubts as I use reselect in a fundamental part of my RN app, thank you so much!
@karldtrumpeter
@karldtrumpeter 3 жыл бұрын
Thank you, this really helps.
@matej-world
@matej-world 5 жыл бұрын
Interesting thing to look at for global state is 'reactn' library, it support hooks as well as classes and is way cleaner than Redux or MobX
@IvanKleshnin
@IvanKleshnin 5 жыл бұрын
Did you try SSR with ReactN?
@matej-world
@matej-world 5 жыл бұрын
@@IvanKleshnin no Ivan, just on some mobile projects
@CesarGonzalez-np2oe
@CesarGonzalez-np2oe 5 жыл бұрын
Thanks for the vid! Just starting to learn React and now I'm learning about Redux I'd have the points you made on the video in mind
@kbutube
@kbutube 2 жыл бұрын
Cool use of refs here for tracking re-renders!
@qwerduro
@qwerduro 3 жыл бұрын
Simply delivered… keep it up
@namanjindal1399
@namanjindal1399 2 жыл бұрын
Simple and to the point!
@worldclasscode1847
@worldclasscode1847 2 жыл бұрын
Great video! But where is the source code?
@juancamiloq1
@juancamiloq1 5 жыл бұрын
Awesome.
@boyswillbeboys6177
@boyswillbeboys6177 4 жыл бұрын
so, using context is bad if you are creating game or some sort, where you can spam buttons and data were stored locally? Coz in most web applications with separate frontend, it usually waits a response from api at the backend on every requests.
@engenglish610
@engenglish610 4 жыл бұрын
Thanks @Ben Awad, it's possible to use multiple contexts to deal the presented issue (rendering) ?
@robertshawnmitchell
@robertshawnmitchell 5 жыл бұрын
What about useReducer() ?
@tkdevlop
@tkdevlop 5 жыл бұрын
useReducers can only be used in it's own component or pass down as props therefore it cannot be consume as context in any child component. PS - pls correct me if I miss something
@7833497
@7833497 5 жыл бұрын
@@tkdevlop Technically you can pass usereducer reducer as context with both state and all actions you can perform, but i'm not sure how it would click in the end
@bawad
@bawad 5 жыл бұрын
useReducer is great for local state for state across multiple components, you can combine it with context but you'll run into the same problem
@nicken86
@nicken86 5 жыл бұрын
Would breaking it down to multiple contexts be a viable solution?
@bawad
@bawad 5 жыл бұрын
it can be depending on the situation
@AngryBeaver999
@AngryBeaver999 4 жыл бұрын
Can I get the data inside Likes component without using provider? I mean I would like to get "likes" data in Navbar component, If i call I will also render updated data there? Should I use some kind of consumer? I am not sure
@sunclaude
@sunclaude 3 жыл бұрын
In my opinion: Redux is a smelly imitation of Dependency Injection where the state has been made more abstract. This adds a tree of garbage classes to Your project (still readable but garbage). Using it it's like inverting binary trees at google.
@IamAWESOME3980
@IamAWESOME3980 4 жыл бұрын
Can't you just use life cycle method like should components update to prevent unneccesary rerendering?
@AR-yr5ov
@AR-yr5ov 2 жыл бұрын
420k subs nice.
@rayvincentdelacruz8251
@rayvincentdelacruz8251 5 жыл бұрын
Hello Ben please help, I am wondering why this code is not working? state = { todos: [...state.todos, payload], flashMsg: { type: "success", msg: "Sweet! Successfully added todo" } }; but this code works state.todos = [...state.todos, payload]; state.flashMsg = { type: "success", msg: "Sweet! Successfully added todo" } I just don't like using this way
@bawad
@bawad 5 жыл бұрын
both are bad you should be calling setState
@JaviGomez
@JaviGomez 5 жыл бұрын
Simple: Use Context sparingly. Don’t use redux ever. If you need globals in any program they have to be necessary. GLOBALS ARE BAD. If you need something more than React hooks for state you are doing something wrong. If you need to pass context down to deep sub children - rewrite your code it’s too complicated. I think traveling outside of JS land can be helpful for React devs.
@zes7215
@zes7215 Жыл бұрын
no such thing as have tox or etc or more or costx or lx or not etc, outx, can outx infix etc any nwm s perfx
@myworldbox
@myworldbox Жыл бұрын
you dont need redux, usereducer can do anything if you truly understand it
@Bread-vk8fl
@Bread-vk8fl 5 ай бұрын
So basically CONTEXT will re-render the component even if its not used. With REDUX it doesn't happen.
@unlimitself
@unlimitself 5 жыл бұрын
Open to trying Svelte?
@IvanKleshnin
@IvanKleshnin 5 жыл бұрын
It won't beat React because of the ecosystem. It's too late in 2019 to enter the framework battle. I personally wouldn't waste time to learn another "promising" framework. There are better topics to spend your time on.
@bawad
@bawad 5 жыл бұрын
I tried the getting started and it was pretty cool, but I'm not ready to switch from react
@unlimitself
@unlimitself 5 жыл бұрын
@@bawad I am in the same situation. I like the React (everything JS) concept. I don't want to learn a new templating standard. I wish React introduces some kind of precompilation to avoid larger size bundle etc. But we have to realize that there is no Status Quo in our world. A new better one will always replace an old less good one.
@unlimitself
@unlimitself 5 жыл бұрын
@@bawad Check this out kzbin.info/www/bejne/d5Wxe2acrsmYl9E
@unlimitself
@unlimitself 5 жыл бұрын
@@IvanKleshnin Check this out kzbin.info/www/bejne/d5Wxe2acrsmYl9E
@sh_zik
@sh_zik 5 жыл бұрын
checkout "effector", u will be glad.
@alex_chugaev
@alex_chugaev 3 жыл бұрын
useAngular
@cancer10in
@cancer10in 4 жыл бұрын
Can someone please add a tldr of this video?
@rohandevaki4349
@rohandevaki4349 4 жыл бұрын
you could have shown using redux , but you used "easy-peasy", why?, the title of the video itself is redux vs context, you should have really shown redux and useContext, this is not good bro.
@H3000-v7i
@H3000-v7i 4 жыл бұрын
easy-peasy is Redux with an abstraction layer...
Learn useReducer In 20 Minutes
20:12
Web Dev Simplified
Рет қаралды 526 М.
Context vs Redux: What to Choose? - Experts Zone #6 | frontendhouse.com
6:40
Liki Podcasts (Frontend House)
Рет қаралды 25 М.
Маусымашар-2023 / Гала-концерт / АТУ қоштасу
1:27:35
Jaidarman OFFICIAL / JCI
Рет қаралды 390 М.
Context API in react | get the concept
29:00
Hitesh Choudhary
Рет қаралды 77 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 498 М.
Redux Tutorial (with Redux Toolkit)
19:28
Net Ninja
Рет қаралды 351 М.
7 React Lessons I Wish I Knew Earlier
7:30
Code Bootcamp
Рет қаралды 77 М.
Beginner React.js Coding Interview (ft. Clément Mihailescu)
36:31
Ben Awad
Рет қаралды 2,2 МЛН
Should you still be using Redux in 2023?
7:35
Matt Pocock
Рет қаралды 53 М.
React Hooks Tutorial
1:45:07
Ben Awad
Рет қаралды 240 М.
How to use memo in React to Optimize Renders
11:45
Ben Awad
Рет қаралды 65 М.