Тёмный

How I Manage State in React 

Leigh Halliday
Подписаться 33 тыс.
Просмотров 33 тыс.
50% 1

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

 

4 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 221   
@leighhalliday
@leighhalliday 3 года назад
Check out my new course called Next Level Next.js! A full stack course covering GraphQL, TypeScript, Apollo, Prisma, Mapbox, Auth and lots more! courses.leighhalliday.com/next-level-next-js Is the cost prohibitive? Hit me up on Twitter (twitter.com/leighchalliday) and I'll get you a Purchase Price Parity coupon code. Same goes for students.
@Aiducateur
@Aiducateur 3 года назад
someone give this fellow Canadian a Nobel price for "clarity of explanation". clear concise and so well explained... Bravo!!! I wish I had seen this video months ago...
@Vreth6
@Vreth6 4 года назад
There was nothing new in this video for me, but I loved watching it anyway! This presentation was very well executed and i'm excited to see what you come up with in the future. Good job!
@leighhalliday
@leighhalliday 4 года назад
Thank you MaDah! Glad you enjoyed it :)
@KirkQuesnelle
@KirkQuesnelle 3 года назад
yeah same, I love going back to the fundamentals after I did a deep dive of learning and had some experience under my belt. You almost get a new sense of confidence and reinforcement. I already said this but Leigh, your teaching style is really really good!
@jimshtepa5423
@jimshtepa5423 3 года назад
same here. I love how Leigh structure and separate concepts by sections. thank you
@bentoman
@bentoman 4 года назад
This video has maybe the best thumbnail of any video ever.
@leighhalliday
@leighhalliday 4 года назад
I knew the mullet would perform well :)
@faisalamin001
@faisalamin001 2 года назад
sooo clear and straightforward, thank you!!!!
@bryceblankinship
@bryceblankinship 2 года назад
Thanks for this! Finally clarified my confusion as to what I should to when trying to pass state between components... I didn't know that was referred to as "lifting state". Thanks!
@leighhalliday
@leighhalliday 2 года назад
Nice! Glad it helped! What’s a cosmic peach?
@bryceblankinship
@bryceblankinship 2 года назад
@@leighhalliday it’s an old username for Minecraft 😂
@gabriellinassi3382
@gabriellinassi3382 2 года назад
Man it was very clarifying. Thanks!
@Whodidthis12345
@Whodidthis12345 3 года назад
You are the best teacher I’ve found. Really appreciate it, Leigh
@leighhalliday
@leighhalliday 3 года назад
Thanks Andrew! Glad my teaching style connects with you :D
@RomanFilenko
@RomanFilenko Год назад
Great explanation, Leight
@ArranMaclean
@ArranMaclean 4 года назад
Would love to see it covered with unit tests. Great video
@Famouzi
@Famouzi 4 года назад
Yeah
@leighhalliday
@leighhalliday 4 года назад
Great idea, thank you Arran!
@eduardohidalgo5260
@eduardohidalgo5260 4 года назад
This video should be see it by all React Developers. Few people are talking about ways of state management. I love your content (: Grettings from México!
@leighhalliday
@leighhalliday 4 года назад
Gracias Eduardo! Corre la palabra :D Cheers from Canada!
@martinmaldonado4923
@martinmaldonado4923 4 года назад
I used to avoid context due to the unnecessary re-renders, will definitely check it out now! Thanks!
@leighhalliday
@leighhalliday 4 года назад
Yea! Definitely try to memoize that component right under the context.
@xandmore
@xandmore 4 года назад
​@@leighhalliday ​ I think you're mistaken here. Every component, that uses context (via useContext) will be rerendered as far as the context's value is changed. Another thing i'd like to mention is that usage of context makes your code more difficult to test. The Law of Leaky Abstractions term is applicable here I think. After you provide context and your component consumes it - you have to look into your black box because inputs are not the props anymore. Please, give some feedback about this
@jacksto123
@jacksto123 3 года назад
very helpful. great explanation of how to create context and why it is useful
@antoniyo182
@antoniyo182 3 года назад
Keep up the good work man, I'm a big fan. Clear and concice
@leighhalliday
@leighhalliday 3 года назад
Thank you very much Jesus! :)
@andyslezak3606
@andyslezak3606 4 года назад
Another great vid. Thanks, Leigh!!
@leighhalliday
@leighhalliday 4 года назад
Thank you Andy :)
@olawaseem
@olawaseem 4 года назад
Thank you , this video like a handbook for react state management using hooks in a clear way
@leighhalliday
@leighhalliday 4 года назад
Thanks Waseem, glad you enjoyed it!
@abessesmahi4888
@abessesmahi4888 4 года назад
Fast, Easy, and Clear. Thank you so much.
@leighhalliday
@leighhalliday 4 года назад
Thanks for watching, Abesse :)
@landonschlangen
@landonschlangen 4 года назад
Very solid video. It's amazing that you didn't make any silly mistakes when writing the code.
@leighhalliday
@leighhalliday 4 года назад
Hey Landon! That's because I made all the silly mistakes on my own as I was prepping lol
@ShahidShafique
@ShahidShafique 3 года назад
Thanks for clearing concepts ..
@leighhalliday
@leighhalliday 3 года назад
You're very welcome Shahid!
@noura4086
@noura4086 4 года назад
such an amazing smooth presentation that covered various important topics :))
@leighhalliday
@leighhalliday 4 года назад
Thank you EgR!
@subratsingh6204
@subratsingh6204 3 года назад
Great Video. Thank you for sharing this !
@leighhalliday
@leighhalliday 3 года назад
Thank you Subrat!
@TheApplePooch
@TheApplePooch 3 года назад
Thank you! 🙌 You explained it really well sir and before this I was unsure about the state management in react you did great 🙌🙌🙌🙌🙌🙌🙌🙌🙌
@leighhalliday
@leighhalliday 3 года назад
Thank you very much Khairul! :)
@andreacappuccio58
@andreacappuccio58 4 года назад
Was just about to ask you to share your state management mental structure... great to see video this in my feed right now!
@leighhalliday
@leighhalliday 4 года назад
Thanks Andrea! I hope you enjoy it!
@VincentFulco
@VincentFulco 4 года назад
This was really an outstanding video. it seems others have addressed each of these use cases in isolation but I have yet to come across something as clear and comprehensive. Thank you!
@leighhalliday
@leighhalliday 4 года назад
Awesome! Thank you Vincent, I'm glad you enjoyed it!
@Allyourneedsmet
@Allyourneedsmet 3 года назад
I agree.
@abhinav.sharma
@abhinav.sharma 4 года назад
I was figuring out this whole thing, a few moments before this video dropped, Thanks Mr. Halliday.
@leighhalliday
@leighhalliday 4 года назад
Nice! Happy the vid could help :) You're welcome Mr. Sharma.
@ignaciodelamadrid
@ignaciodelamadrid 4 года назад
I really really like the pace of your tutorials Leigh! You really have a gift for explaining things and keep people interested. Looking after more content from you!
@leighhalliday
@leighhalliday 4 года назад
Thank you Ignacio!! I'm glad you're enjoying them! I make these to learn myself too! It's how I learn best :)
@bluekeny
@bluekeny 3 года назад
Great explanation... Thank you
@leighhalliday
@leighhalliday 3 года назад
Thank you Kenyon :) Glad you enjoyed it!
@tauraik
@tauraik 4 года назад
This is brilliant I've been struggling with understanding state thank you so much and you explained it so well thank
@leighhalliday
@leighhalliday 4 года назад
Nice! Glad you enjoyed it and that the video helped :)
@RRits57
@RRits57 3 года назад
This is high quality content
@leighhalliday
@leighhalliday 3 года назад
Thank you Riekus! I do my best :)
@sadhucat4476
@sadhucat4476 3 года назад
Great explanation!
@leighhalliday
@leighhalliday 3 года назад
Thank you Sadhu!
@satindersingh9671
@satindersingh9671 3 года назад
There's beauty in simplicity! Love it
@leighhalliday
@leighhalliday 3 года назад
Thanks Satinder! Glad you enjoyed it!
@satindersingh9671
@satindersingh9671 3 года назад
@@leighhalliday looking for more cool react videos from you
@Allyourneedsmet
@Allyourneedsmet 3 года назад
Brilliant!, been trying to understand context and react-query for a while and this cleared it up.
@leighhalliday
@leighhalliday 3 года назад
Awesome! It's not bad once you get the hang of it! Sometimes you just need to see an example eh?
@mateusbentes2679
@mateusbentes2679 4 года назад
Awsome work! Bring us more content like this. Very well explained.
@leighhalliday
@leighhalliday 4 года назад
Thank you :) I'll do my best.
@diogosoares1309
@diogosoares1309 3 года назад
Great lesson Leigh! Thank you 🙏
@leighhalliday
@leighhalliday 3 года назад
You're very welcome Diogo!
@TomHermans
@TomHermans 4 года назад
Another very helpful explanation. I really like the reasoning behind the decisions made or the options chosen. (Yes, I'm a fan of your style of video's)
@leighhalliday
@leighhalliday 4 года назад
Thanks Tom, I appreciate the support!! Lots more videos on the way :)
@AnaBerrocal
@AnaBerrocal 3 года назад
Hey Leigh, great video! I like the way you explain things, very calm and easy to understand.
@leighhalliday
@leighhalliday 3 года назад
Thank you Ana :) Glad you enjoyed the video!
@billpliske
@billpliske 4 года назад
Really nice job with this, Leigh.
@leighhalliday
@leighhalliday 4 года назад
Thank you Bill
@fadilnatakusumah195
@fadilnatakusumah195 4 года назад
Your channel is so awesome
@leighhalliday
@leighhalliday 4 года назад
Thank you Fadil!
@danishmehmood6110
@danishmehmood6110 4 года назад
best react youtuber man
@leighhalliday
@leighhalliday 4 года назад
Thanks :D There's a lot of awesome React RU-vidrs, so that means a lot!
@danishmehmood6110
@danishmehmood6110 4 года назад
@@leighhalliday yes man there are many others who are good but the way you explain and the topics you choose its brilliant
@robovirtuoso1354
@robovirtuoso1354 3 года назад
Recently discovered this simple library called "Simpler State" on Hacker News. I'm currently playing with it... feels like using Context but without Providers. So far looking super simple for the "global state" step you talked about. For Redux, I also like the "Easy Peasy" lib. Nice tutorial btw!
@leighhalliday
@leighhalliday 3 года назад
Sweet! So many state management packages eh?!?
@JS-tg4zp
@JS-tg4zp 3 года назад
So good! If you can, maybe next time include a Github Repo so your viewers can code along. Not necessary, but it'd be nice to be able to code with you. Anyways, great Video!
@leighhalliday
@leighhalliday 3 года назад
Thanks JS... I've been trying to do that but sometimes I forget to do that initial commit haha.
@DarrylHebbes
@DarrylHebbes 4 года назад
outstanding tutorial, well structured and covers so much ground
@leighhalliday
@leighhalliday 4 года назад
Thank you Darryl! Glad you enjoyed it :)
@josemarques8666
@josemarques8666 3 года назад
What a great video, great explanation, great everything!
@leighhalliday
@leighhalliday 3 года назад
Thank you Jotha! Really appreciate it!
@emiliod90
@emiliod90 4 года назад
This was great timing
@leighhalliday
@leighhalliday 4 года назад
Nice :) Glad you enjoyed it.
@KMRakibulIslam
@KMRakibulIslam 4 года назад
Great video as always, Leigh :-)
@leighhalliday
@leighhalliday 4 года назад
Thanks, Rakib :) I appreciate it!
@joaoduarteribeiro
@joaoduarteribeiro 4 года назад
Thanks for your existence.
@leighhalliday
@leighhalliday 4 года назад
lol... I do what I can, but I think my parents deserve the thanks
@geeksy2278
@geeksy2278 4 года назад
What a great video! Thank you so much, made many things very clear! 🚀
@leighhalliday
@leighhalliday 4 года назад
Thank you Geeksy, glad you enjoyed it!
@AryanLokar
@AryanLokar 4 года назад
Great video, i learned more about the state managment especially react query
@leighhalliday
@leighhalliday 4 года назад
Nice! React Query is pretty awesome!
@rubiadias7677
@rubiadias7677 4 года назад
Thank you so much!
@leighhalliday
@leighhalliday 4 года назад
You're welcome, Rubia!
@sheharyarmalik198
@sheharyarmalik198 4 года назад
Great stuff dude. Keep giong
@leighhalliday
@leighhalliday 4 года назад
Thanks Sheharyar! I will keep going!
@nathankrasney
@nathankrasney 4 года назад
Excellent !!
@leighhalliday
@leighhalliday 4 года назад
Thank you Nathan! Glad you enjoyed it :)
@mitsukiorichimaru4511
@mitsukiorichimaru4511 4 года назад
As always great job. For me, context-api with refs brought no problems so far :)
@leighhalliday
@leighhalliday 4 года назад
Thank you Mitsuki!
@thebuildguy7
@thebuildguy7 4 года назад
I came here from a Reddit thread, I loved how you explain every single thing with utmost accuracy. 💙 One more thing, what are the specific use cases for React query? Can't we just handle that with axios and promises?
@leighhalliday
@leighhalliday 4 года назад
Thanks Tulsi! Think of React Query like a wrapper around Axios + Promises (or fetch)... it handles: when to fetch new data, caching, loading state, error states, etc... you can totally combine Axios with React Query.
@thebuildguy7
@thebuildguy7 4 года назад
​@@leighhalliday Thanks man. I like the concept of loading and error state too, they are quite intuitive! Glad I watched your video. :)
@endernator
@endernator 2 года назад
so good my fren thx
@leighhalliday
@leighhalliday 2 года назад
Glad you enjoyed it!
@Tibeb
@Tibeb 4 года назад
Great video !!! Learned a lot in just 17 min !!! The one question I have is what is the difference between useEffect and useQuery if both are executed when a certain value changes. Thank you again
@leighhalliday
@leighhalliday 4 года назад
Hey Tibeb, thank you! useEffect is more general purpose helps you to execute a side effect when a key changes, which could totally be used to load data. useQuery also runs when key changes, but it is specific to loading data, and handles loading state, error state, caching, re-load on focus, etc, etc... it provides a ton of functionality that you would have to build yourself.
@Tibeb
@Tibeb 4 года назад
@@leighhalliday Thank you for the explanation !! Glad I found this channel.
@ShaneGoodson
@ShaneGoodson 4 года назад
I've been using this pattern since context API came out, glad to see I'm not alone, was having an argument with some other devs a while ago about not defaulting to REDUX/MOBx when this is available natively
@leighhalliday
@leighhalliday 4 года назад
Yea, it's pretty great! I say use whatever you feel productive with though :)
@ShaneGoodson
@ShaneGoodson 4 года назад
@@leighhalliday For sure, I just mean a lot of devs go straight to using redux or mobx even for the most simple app state management because it's what they're used to. Those libraries definitely still have their place.
@dannylones2159
@dannylones2159 4 года назад
looking at ur thumbnail i've read title like HOW I MANAGED MY MIND STATE
@leighhalliday
@leighhalliday 4 года назад
lol... so you're saying you love the mullet?
@SirThriveMC
@SirThriveMC 3 года назад
Well done. Great explanation and thorough example. I'd like to see more on context provider though, you didn't mention the default value you passed ("CA"). How would you load that from a fetch call (if you wanted/needed to) for example.
@leighhalliday
@leighhalliday 3 года назад
Hey DaddyDayTrader! Thank you. I think I would load that through a useEffect hook after initial render.
@theasdazx
@theasdazx 3 года назад
Great and clear video. I have one question. In the case of react query, use query returns data, status, error. Is it Okey to store in global state so that I dont have to prop drill the data status or errors. By using this take away the advantage of react query. Do caching and everything still works the same way?
@AnopSinghRanawatperl
@AnopSinghRanawatperl 2 года назад
Thanks
@leighhalliday
@leighhalliday 2 года назад
Glad you enjoyed it!
@lardosian
@lardosian 3 года назад
If I have more than 5/6 contexts in my app is it time to switch to Redux to take advantage of a central store. My workflow is using context api with hooks like useReducer, but having multiple providers for each context seems slightly messy.
@leighhalliday
@leighhalliday 3 года назад
I only switch when I get to 99 providers :D Just kidding hehe.
@malikbrahimi7504
@malikbrahimi7504 4 года назад
Let's say you have some global value like so passed through context: { admin: false, fname: "Jon", lname: "Law" } Let's say the user changes their name to Sam . How would you prevent unnecessary rerenders? This context contains no additional info to split into another context (like an array of movies). The problem with useContext is it subscribes to all changes of value instead of a single key. So first is the issue of optimizing you updater functions in your value with useCallback like setFName for example. Calling setFName would otherwise create a new setFName function based on the fname and trigger a context update and rerenders to all observers that useContext. Furthermore a ProtectedRoute will rerender on setFName although it only cares about the admin key. So how do you address these issues with context?
@leighhalliday
@leighhalliday 3 года назад
Hey Malik! You're right there might be unnecessary renders, but honestly for something like this that isn't updating frequently, I wouldn't worry about it that much. If you are having performance issues, you may want to check out Recoil which solves this sort of problem.
@jamesnguyen5690
@jamesnguyen5690 3 года назад
Thanks, for such a good video Leigh. I was wondering how do you manage state if we have multiple react app build separately then deploy to the server but using the same router. For example, I am going to home/app1 click a button that should transfer data to my home/app2? I wasn't very clear on this. Cheers man
@leighhalliday
@leighhalliday 3 года назад
Hey James! I am honestly not sure of the best approach for sharing state between React apps... maybe through a shared auth token with a backend? Or localStorage? Or through query params?
@SachinYadav-yx1rc
@SachinYadav-yx1rc Год назад
At 10:55 What if the props changed are not primitive data types rather reference data types ?
@arielespanola2109
@arielespanola2109 4 года назад
Awesome works btw @Leigh, how can handle a multiple context provider?
@leighhalliday
@leighhalliday 4 года назад
Hey Ariel! You'd actually have multiple providers, one per context.
@ridl27
@ridl27 4 года назад
ty.
@leighhalliday
@leighhalliday 4 года назад
The pleasure is all mine.
@ginger-viking
@ginger-viking Год назад
@AdamHollister
@AdamHollister 2 года назад
Thanks for the great explanation! Just wondering whether you consider it useful to attempt to maintain state 'as close to the component that needs it' IRL? Or do you tend to pull most state that needs to be used elsewhere out into global state by default? Do you actually ever do prop drilling these days? For example I'm working on something where there's one component that's fed by props from the parent, but pretty much everything else is using global state. Even though I could probably use prop drilling to pass the relevant state around, (components aren't deeply nested), I think I find context and global state a bit simpler to reason about.
@iamchu
@iamchu 4 года назад
I love all of your videos in relation to React, couldn't be more straight forward and informative at the same time. Can I ask, when wrapping the HomeContent component in memo() for the purpose of only triggering re-renders on prop changes, are there any cons to using memo()? And if not, would there be any reason to not wrap all components with memo()? (I appreciate there's probably no need if the component doesn't change prop's state but is there any performance cons to memo for example?
@leighhalliday
@leighhalliday 4 года назад
Hey Iain! I would just let React take care of when to re-render 99% of the time on its own... it'd make your code more complicated for something that might not even help with performance. In this case though it was special because it is the direct child of the context provider... want to avoid it re-rendering any time the state changes.
@chetouihamza7131
@chetouihamza7131 4 года назад
this is a ref tuto like it :)
@leighhalliday
@leighhalliday 4 года назад
Not sure what a ref tuto is, but I will accept it :D Thank you!
@chetouihamza7131
@chetouihamza7131 4 года назад
@@leighhalliday reference tutorial :)
@ThanHtutZaw3
@ThanHtutZaw3 2 года назад
How can I know when I need memo ? How to check I have unnecessary render ?
@rive23
@rive23 4 года назад
Hi, thank you for the video. But I found this in the official doc. “React.memo only checks for prop changes. If your function component wrapped in React.memo has a useState or useContext Hook in its implementation, it will still rerender when state or context change” and I am a little confused
@leighhalliday
@leighhalliday 4 года назад
Hey Carlos! That's actually exactly what I wanted it for. There are no props being passed to it, so it should never re-render unless its internal state changes. Without memo it was re-rendering every time its parent (the context provider) changed.
@rive23
@rive23 4 года назад
@@leighhalliday Ok got it, thank you very much
@ThugLifeModafocah
@ThugLifeModafocah 2 года назад
I started with redux, passed to recoil and then I found context... Contexts are just so better IMHO.
@ericmomoh7927
@ericmomoh7927 2 года назад
The newer version of redux known as redux toolkits is better with less code also.
@meraklicoder
@meraklicoder 4 года назад
what do u prefer using state managment? redux or context? How do u decision?
@leighhalliday
@leighhalliday 4 года назад
Hey Hasan! I think I would always start with this way: - Local state (useState) - Lift state (still useState but in parent component) - Global state (useContext) - If this is not enough, investigate something like MobX
@MrVisheshsingh
@MrVisheshsingh 4 года назад
🥰 wow🤩
@leighhalliday
@leighhalliday 4 года назад
Thanks Vishesh!
@deadbluescreen3101
@deadbluescreen3101 4 года назад
Ciao Leigh, Provider is smart enough and re-renders only children components that actually consume the context. In this particular case you don't need memo.
@leighhalliday
@leighhalliday 4 года назад
I was going off of Sophie's tweet who was on the React Core team that this was a good suggestion: twitter.com/sophiebits/status/1228942768543686656
@neildaly3143
@neildaly3143 4 года назад
Great video Leigh! What theme are you using for Vs code?
@leighhalliday
@leighhalliday 4 года назад
Thanks! Monokai One I believe?
@rangabharath4253
@rangabharath4253 4 года назад
awesome
@leighhalliday
@leighhalliday 4 года назад
Thank you Ranga!
@aissa.bouguern
@aissa.bouguern 4 года назад
What if we need country fetched data in another component ? Does useQuery() hook know that those two components are fetching the same data ?
@justaddwater57
@justaddwater57 4 года назад
Yes. Behind the scenes it does some complex caching so that if another component needs the 'CA' data and it's already fetched it once before, it will know to reuse it, depending on the cache policy you've set, or re-fetch it if the cache is stale. All of those external data libraries have some version of this and it's really cool! No more fussing with redux sagas or thunks, or managing loading states or any of that stuff.
@aissa.bouguern
@aissa.bouguern 4 года назад
@@justaddwater57 Thank you William!
@leighhalliday
@leighhalliday 4 года назад
Great answer from William Wong!
@sahassaurav4144
@sahassaurav4144 3 года назад
Can you share the really project repo where you manage global state with content and server state with react query?
@leighhalliday
@leighhalliday 3 года назад
Hey Sahas! Sorry... I don't think I have a public one to share. But, I do have a course where we have both global state with context and server state with Apollo Client (GraphQL). You may want to check it out! courses.leighhalliday.com/next-level-next-js
@sahassaurav4144
@sahassaurav4144 3 года назад
@@leighhalliday I will try to buy it when I will save enough money
@xxxxdddddss
@xxxxdddddss 2 года назад
what about a user state (after login), how would you manage it? since there is lot of data like tokens, user type and stuff
@xxxxdddddss
@xxxxdddddss 2 года назад
also Im not sure if you have made video about that but it would be great to see how you manage renewing the tokens or overall the whole authorization part
@HpDopeman
@HpDopeman 3 года назад
Hey, can you provide the list of extensions you are using in VSCode ?
@leighhalliday
@leighhalliday 3 года назад
Oh man, so many... I'm not going to manually list them haha :D
@lexb682
@lexb682 4 года назад
Awesome! Is there a way to use global state also with getStaticProps and Dynamic Routes (Next JS)?
@leighhalliday
@leighhalliday 4 года назад
Hey Lex! It just arrives as props to your page, so you could probably use the prop value from the page as the initial value in your context and then share it that way.
@Norfeldt
@Norfeldt 3 года назад
Would you but external state from react query into a context or would you extract it from react query in components lower lower down that needs to read part of the data.
@leighhalliday
@leighhalliday 3 года назад
I guess it totally depends where I need the data... I don't think there is a universal answer. In a context could be a good way to make it universal in your app.
@akmutik6259
@akmutik6259 3 года назад
Hi U shouldn't use context as global state replacement only use when data don't change much like theme user details app settings
@leighhalliday
@leighhalliday 3 года назад
Says who? :D
@akmutik6259
@akmutik6259 3 года назад
@@leighhalliday React team and react documentation
@akmutik6259
@akmutik6259 3 года назад
@@leighhalliday Before You Use Context Context is primarily used when some data needs to be accessible by many components at different nesting levels. Apply it sparingly because it makes component reuse more difficult. If you only want to avoid passing some props through many levels, component composition is often a simpler solution than context.
@akmutik6259
@akmutik6259 3 года назад
@@leighhalliday When to Use Context Context is designed to share data that can be considered “global” for a tree of React components, such as the current authenticated user, theme, or preferred language. For example, in the code below we manually thread through a “theme” prop in order to style the Button component:
@xingyahao4106
@xingyahao4106 4 года назад
How to edit state come from api? Simply thinking a edit page.
@leighhalliday
@leighhalliday 4 года назад
Hey Xing! At that point I think you'd have to put it in actual state, because it goes from "server" state to "app" state when you start to edit it. You could use the response from useQuery as the initial value of your state.
@rtnjo6936
@rtnjo6936 4 года назад
sir, whats your opinion about vue? there is so hype around it, especcially about state managment, no need such things like redux, you just change state of component and vue magicly does all thing for you. I allredy learning react, but i really jealos about all of that in vue, and people say that it's one of many features that vue has, what is your vue vs react opinion?
@leighhalliday
@leighhalliday 4 года назад
Hey! I haven't really looked into Vue... it looks like it has a great community, but I feel like there are so many things I want to learn in the React community (Redwood!) that I haven't felt the need to go look deeply.
@sayhitopizza
@sayhitopizza 3 года назад
Hey Leigh! I noticed that without the use of 'memo' for HomeContent, HomeContent still isn't being rerendered when the context is changed via button click in CountryPicker. I was wondering if anything changed since this video? I tested it by console.logging within HomeContent before the return.
@leighhalliday
@leighhalliday 3 года назад
Hey Derek! I'm not entirely sure to be honest... I wouldn't worry too much about memo unless it actually causes performance problems for you.
@chamir4614
@chamir4614 4 года назад
which one do you prefer. swr or react query?
@leighhalliday
@leighhalliday 4 года назад
Both are cool! I don't want to pick sides, follow your heart.
@pranavpatil5849
@pranavpatil5849 3 года назад
Question: how could we have a managed state in react-query.. like here execution of fetchCountry is not in our control.. if u had to call it conditionally/onmount then how it could done?
@leighhalliday
@leighhalliday 3 года назад
Hey! On mount it would be called automatically, but if you want it to be conditional, I would actually move it to a sub-component which is only rendered if it should actually do the HTTP call. Break the big component into smaller ones... they can even just live in the same file.
@pranavpatil5849
@pranavpatil5849 3 года назад
@@leighhalliday Great.. thanks..
@willcalltickets
@willcalltickets 4 года назад
So does useQuery memoize the data? Or does it do a new fetch every time the selection is changed? If it does memoize, how can we force a new fetch?
@neildaly3143
@neildaly3143 4 года назад
It refetches when the first argument to useQuery changes
@leighhalliday
@leighhalliday 4 года назад
Yes, but useQuery has a caching strategy for you to control when it refetches and there is a way to force it to refetch manually as well. Check out their docs for more details.
@ubaidkhan426
@ubaidkhan426 2 года назад
My manager won't let me to use external libs for the state management 😭
@smartvivek89
@smartvivek89 2 года назад
What font and theme please ? 😃
@leighhalliday
@leighhalliday 2 года назад
OneMonokai is the theme, font is fira mono I believe
@julixx_btc
@julixx_btc 3 года назад
Double like for not mispronouncing Colombia 🇨🇴
@leighhalliday
@leighhalliday 3 года назад
Ya tu lo sabes!
@ianbase646
@ianbase646 3 года назад
what would happend if i want to share server data with other parts of applications or update other part of component
@leighhalliday
@leighhalliday 3 года назад
You could potentially load it with react-query at a higher level in your app, and then share it via context to other parts of your application.
@ianbase646
@ianbase646 3 года назад
@@leighhalliday thank you leigh i have already some redux setup with hundred components honestly pain in a. thanks again your tutorials are amazing
@berlino5563
@berlino5563 4 года назад
Try jotai :))
@leighhalliday
@leighhalliday 4 года назад
I'll add it to the list!
@amjedbouhouch7993
@amjedbouhouch7993 4 года назад
useQuery 😍
@leighhalliday
@leighhalliday 4 года назад
It's great, eh?
@laser1915
@laser1915 4 года назад
Redux will always be the best
@leighhalliday
@leighhalliday 4 года назад
So will Visual Basic 6!
@muaddib878
@muaddib878 3 года назад
One word: Mobx!
@saivivekravi4979
@saivivekravi4979 3 года назад
Can you send me your setting.json I like your code editor theme and and all other stuff
@leighhalliday
@leighhalliday 3 года назад
I encourage you to explore your own customization :D
Далее
Immutable Data Without Pain & Suffering
21:44
Просмотров 3,3 тыс.
Mastering React Context: Do you NEED a state manager?
37:26
КОГДА НАКРОШИЛ НА ПОЛ #shorts
00:19
КОТЯТА НАУЧИЛИСЬ ГОВОРИТЬ#cat
00:13
The Most Important Design Pattern in React
35:04
Просмотров 61 тыс.
Implement Clean Architecture in Next.js
53:07
Просмотров 23 тыс.
Modern Data Fetching in React (Complete Guide)
16:41
Просмотров 51 тыс.