Making React Context FAST!

  Рет қаралды 88,366

Jack Herrington

Jack Herrington

Күн бұрын

Пікірлер: 438
@norberthorgas2428
@norberthorgas2428 Жыл бұрын
I have been working with React for about 4 years and recently started teaching React to juniors. Today I feel like I am a junior again 😀 Thanks for sharing this amazing content Jack!!
@ljuglampa
@ljuglampa Жыл бұрын
I've made this "fast context" solution a few times. The thing is, you don't even need any Provider here. You can just use any external object with the same pub/sub api, since we're triggering re-renders manually, so this useStore hook can pick its store from wherever, not just from a context. Also, when you do useRef(new Set(...) you're re-creating this Set for every render of that custom hook. It won't care about the value but still, it's "cleaner" to do: if (!store.current) store.current = new Set(...) to make it just happen once. Otherwise awesome content Jack. I love the useSyncExternalStore abstraction to get rid of setting up local states manually. Feels safer also to have React internals take care of that part.
@untitleddocument4197
@untitleddocument4197 Жыл бұрын
Good point :D I guess this also means you could use a store that syncs with localstorage, if it made sense too
@PeerReynders
@PeerReynders Жыл бұрын
The Provider and the `useStore()` hook are fine. They decouple the components from the source which is useful for developer tests and for inclusion in design system guides. However, especially as `useSyncExternalStore` is being used, there is no need for `useStoreData()` to be a hook so it can just be implemented as a vanilla `createStore` function without all the `useRef()`and `useCallback()` complexity. Also since the properties in the created { set, get, subscribe } object are stable through the lifetime of the application it makes sense to just bind it to a `store` variable within the closure created by `createFastContext()` that both `createContext` and `StoreContext.Provider value` can use to eliminate the initial `null`.
@asdfasdfuhf
@asdfasdfuhf 2 ай бұрын
@@PeerReynders "so it can just be implemented as a vanilla createStore function without all the useRef and useCallback complexity" -- are you suggesting to just use `let var = ...` variables instead of useRef? I.e. rewrite createStore to be pure javascript, no react?
@nikolagospodinov9057
@nikolagospodinov9057 Жыл бұрын
Jack, thank you for all your videos! Thanks to you I leveled up my skills and got to a senior position! I hope you come out with a course soon describing all of the mid/advanced React concepts, best practices, project structuring, when and how to use 3rd party libraries like RQ, state management, and all those good stuff. I would literally pay anything for that!
@jherr
@jherr Жыл бұрын
'Anything'? I can imagine? kzbin.info/www/bejne/qIuleZyqqJ19hqs
@quelchx
@quelchx Жыл бұрын
React Query as some excellent documentation -- dedicate a day to browse through it and you will be surprised what you will be able to accomplish with that library. My companies application has some complicated state between the server and client and react query has made it so easy to manage state, handle mutations + hydrating the client. It only took me a few days of going through the documentation and now I feel fluent with talking to that library -- it shouldn't take you very long if you dedicate a few hours to it.
@jherr
@jherr Жыл бұрын
@@quelchx kzbin.info/www/bejne/gJKwY6V7rdKgp9U
@quelchx
@quelchx Жыл бұрын
@@jherr I have watched this video =). When I first used RQ I thought it was more for data fetching and managing it's state but I have used it to simply manage state from one component to another and mutate that state. I love RQ it's such a useful tool. Honestly Jack I have learned a lot through your content and have taken patterns you have provided and I use them daily =).
@jherr
@jherr Жыл бұрын
@@quelchx Thank you so much!
@alexlohr7366
@alexlohr7366 Жыл бұрын
Small remark: if you are storing your data in a ref in any case, there is no need to overwrite it with a new object that destructures both the current data and the updates, instead use Object.assign to copy over the partial values for a little better performance. Otherwise, this is a nice pattern and you've done a great job showing how it comes together, @Jack Herrington!
@talatkuyuk6556
@talatkuyuk6556 Жыл бұрын
How ? [line-22] if I use Object assign ------> store.current = Object.assign(store.current, value); but TypeScript says (Type 'Partial' is not assignable to type 'Store')
@alexlohr7366
@alexlohr7366 Жыл бұрын
@@talatkuyuk6556 in this case, you can cast value to store. This is a shortcoming of TypeScript.
@talatkuyuk6556
@talatkuyuk6556 Жыл бұрын
@@alexlohr7366 Nope, I casted the value as Store; but Object.assign first parameter should extend {} in nature; TypeScript is still angry.
@mortezatourani7772
@mortezatourani7772 Жыл бұрын
@@talatkuyuk6556 What about this: `Object.assign(store.current, value);`
@PeerReynders
@PeerReynders Жыл бұрын
@@talatkuyuk6556 You have to constrain Store's type-note below the `Store extends Record`: export default function createFastContext(initialState: Store) { … const set = useCallback((value: Partial) => { Object.assign(store.current, value); subscribers.current.forEach((callback) => callback()); }, []);
@nathanfranck5822
@nathanfranck5822 Жыл бұрын
Jack writing a solid library in real-time is just incredible. Love to see it and super empowering for anyone looking in to see that you don't need 100 npm packages in your project to make something super solid and robust! The more code that you can own and understand yourself now means more flexibility and creativity later as you figure out what your project is and can be. Also helps even if you're using pre-built libraries to explore in code yourself to know exactly what you want out of a library and cut through all the bullshit you don't need.
@monastyrskiiden
@monastyrskiiden Жыл бұрын
What a wonderful explanation, I've been working with React for over 4 years already, and still, there's something new I get to discover every day.
@quelchx
@quelchx Жыл бұрын
Using React Context and patterns like what you have shown too me is more than enough for a bunch of use cases. I'm glad to see a video like this so I can point some of our developers we hire to this video to get a gist of what I call baked into React for global state management using HOC patterns. Im sure I'm not alone with feeling like this but once you learn a few state management patterns/libraries (Zustand, Jotai, React Query, Redux, React Context patterns) I enjoy using almost all of them and when it comes to making a choice on which one to use I often struggle to make a choice because they are all great IMO (for React apps) Thanks again for all the content you provide to the React Ecosystem it's great, absolutely love the content -- your a great guy for all the work you provide towards developers coming into this gig.
@mortezatourani7772
@mortezatourani7772 Жыл бұрын
Let's make react context great again :) I think the actual implementation of context should be something like this and the current version is really deficient. And again really enjoyed the way you went step by step, improved the solution, and made it generic. It not only helps with understanding the process but also demonstrates how to eat an elephant. Thanks again.
@DEVDerr
@DEVDerr Жыл бұрын
You have almost introduced fine-grained reactivity to React like it is for Solid and Svelte. Fantastic job 🔥 Wondering why React did not yet implement such a thing lol
@josephizang6187
@josephizang6187 Жыл бұрын
Thank you Jack, the time you take to make your content..with so much thought and care makes every video a gem. Again, thank you.
@igogs7095
@igogs7095 Жыл бұрын
Such a great lesson! This channel is diamond for ones who wanna become really good at react! Awesome job, thank you!
@igrb
@igrb Жыл бұрын
This was so instructive, I love how you teach not only these cool patterns but the reasoning behind them AND colol little details like the Partial there. Thanks Jack!
@loia5tqd001
@loia5tqd001 Жыл бұрын
I'm really interested in seeing how this would get involved in a more complex application, please do so Jack. For example: - involving async actions - actions that need states from different stores or fields of store
@creatorsremose
@creatorsremose Жыл бұрын
Jack, it's like you're following my work and post videos that are surgically relevant to my challenges. You're so awesome. Thank you so much.
@wonjunjang3839
@wonjunjang3839 Жыл бұрын
This is so high-quality as a junior frontend dev your contents are really helping me write neat-codes,
@scottsmith416
@scottsmith416 10 ай бұрын
I've been looking for a solution like this for years! Thanks, Jack!
@bushigi5913
@bushigi5913 Жыл бұрын
What kind of solution is this!! You just made my understanding of react to another level! Thank you so much, I'll definitely come back to watch this video again and again.
@Chrosam
@Chrosam Жыл бұрын
I haven't seen the video yet, but based on previous videos I know it's gonna be amazing. I like that you don't only show HOW to do it, but WHY you do it. Here, you dropped this, king 👑
@Chrosam
@Chrosam Жыл бұрын
Done, yep, as expected, never fails to amaze.
@matt35953
@matt35953 Жыл бұрын
Jack, you a a legend! Spent most of yesterday looking at state mangers to address this kind of issue... glad I took a "KZbin break."
@Nonsense116
@Nonsense116 Жыл бұрын
I was able to predict what direction you were going to go as you went along. When I first started watching your channel a lot of what you talked about sounded like voodoo magic. The only reason I was able to predict before hand what you would do is because people like you are incredibly skilled and offer up high quality educational content. I often reference or recommend this channel to my coworkers. I really can't thank you enough and I still learned something new as I normally do with your videos. Thank you for being a part of keeping my skills fresh and staying highly motivated to stay curious.
@MajdBaddour
@MajdBaddour Жыл бұрын
A superb solution, refactored to perfection. That was an excellent video, as always. Thank you Jack for all you do.
@parsanasirimehr7267
@parsanasirimehr7267 Жыл бұрын
I love it when these type of ideas come along. I wouldn't use it for state management, but it has a lot of potential when it comes to Multilayer contexts that I deal with at work. It piles up little by little. Thanks Jack
@pablocubicomusic
@pablocubicomusic Жыл бұрын
I see `useStore` is in the same scope as the components since they all live in the same file. But how could you extract useStore to use it in other places, splitting code into more failes?
@lilpodbebe
@lilpodbebe Жыл бұрын
Brilliant! I need this to maintain a complex form without a complete rewrite. Thank you! 🤩
@AlJey007
@AlJey007 Жыл бұрын
I was playing around with your code and came to a realization that the magic is entirely in the useSyncExternalStore method and the context is 100% superfluous, it is not doing anything at all. In fact, useRef and useCallback are also redundant. With a few tiny tweaks this useful code became a game changer for me. Thank you for this video!
@mrasoahaingo
@mrasoahaingo Жыл бұрын
I really love the way you explain concept by doing step by step. It reminds me of Dan Abramov trying to re implement Redux from scratch. It make things clearer and straightforward. Really really enjoy your video format! Thanks!
@ynonshoshan
@ynonshoshan Жыл бұрын
in my eyes this should be an essential upgrade to react and should be an available hook that comes right out of the box, thanks for this!
@axe-z8316
@axe-z8316 Жыл бұрын
Hey long time interested, but now full fledged fan, this is hands down your best stuff to date. Amazing
@shivamjhaa
@shivamjhaa Жыл бұрын
At this point, I don't really know how you keep coming up with a new cooler video. Thanks, from India
@sissipwns
@sissipwns Жыл бұрын
Omg just realizing that context is initially designed for slow-changing-stuff really enhanced my mental model of React. Thanks so much for your videos, you are the coding buddy I don't have :)
@JhonLavigne
@JhonLavigne Жыл бұрын
Jack, this is by far the most interesting video about state management in React that I have ever seen. Holy shit, Sir. you are a Beast.
@zachatack21
@zachatack21 5 ай бұрын
This is an absolutely incredible tutorial! I learned a ton from this! I understand context, useRefs, and how components rerender SO much better now! Thank you!!!
@frostmichael8360
@frostmichael8360 Жыл бұрын
It's a rainy and windy sunday, i drink a cup of tea and i'm definitly fallen in love with your code and conception. Thank you !
@kelvinklee
@kelvinklee Жыл бұрын
This is pretty awesome, I am curious how close a small lib like Zustand is basically just this general structure with a few more features? Good to see what's going on behind the scenes. Thanks for always sharing amazing content!
@Rico-cp4xp
@Rico-cp4xp Жыл бұрын
I can't tell you how much I appreciate your videos Jack. You're a great teacher! 🙏
@cristiang4774
@cristiang4774 Жыл бұрын
This tutorial blew my mind (in a positive way). Amazing stuff!
@robwatson826
@robwatson826 Жыл бұрын
That pub/sub solution is great! I'm relatively new to React and hadn't considered that as a way to manage state "globally" and only re-render components that need to. Thanks for sharing this Jack
@marouaniAymen
@marouaniAymen Жыл бұрын
In my experience, I use React context when it is limited in a very narrow part of the components tree, when the state to share is not internal and will wrap a big part of my application, I use Redux Toolkit, I found it very awesome. For server state management, react-query for sure.
@marlonmarcello
@marlonmarcello Жыл бұрын
Love your content Jack, thanks for this great explanation! I am a React dev, I work with it every day, and this kinda of hassle that we have to go through to get this level of performance is one of my biggest pet peeves with the framework. For my freelance projects I use Svelte and I get all of that for free, it's glorious. Looking forward to a video on the new upcoming SvelteKit!
@clouatre3034
@clouatre3034 Жыл бұрын
It's incredible how much I have learned from you. Thank you once again!
@quadro201
@quadro201 Жыл бұрын
Hey man, please never stop making videos. I learn so much from you. It has been a year since I've been working full time on react apps and there hasn't been a day without something new. Thankyou.
@alanrice9935
@alanrice9935 Жыл бұрын
Great explanation, I've been toying around with using this context pattern and you explained some parts that I couldn't figure out
@beemanik
@beemanik Жыл бұрын
My first comment to you. Your videos is super useful and straightforward. I like using Redux, but Context is super for local high state around piece of tree. I wish you GL and thanks for sharing your experience .
@riman8493
@riman8493 Жыл бұрын
This was quite amazing and answers a pretty real need I actually have right now. Thank you _so much_ for putting this out there!
@mysandyballs
@mysandyballs Жыл бұрын
Exactly what I was looking for to take context to the next level. Great work as always Jack 👍
@somewonderfulguy
@somewonderfulguy 6 ай бұрын
I really love this combo. I'm going to use fast context in UI kit I develop (for fun and practice) as I see it reasonable to use React context instead of any 3rd party state management. Less dependencies better for UI kit. I made one modification, inside Provider component there are two providers now - one provides 'set', the other 'get' and 'subscribe'. And instead of useStore there are useStoreValue and useStoreDispatch now. There are cases when you have store setter that does not care about value, so component that uses setStore will never re-render as 'set' is always stable. Thanks for the video and solution it is awesome!
@hugot8226
@hugot8226 Жыл бұрын
That's SO VALUABLE Jack ! I was looking for a solution for exactly this problem for months. What an elegant solution !
@DIN_A8
@DIN_A8 Жыл бұрын
I never get tired of the view, what a zen-place to work from
@KPOPYakuzaz
@KPOPYakuzaz Жыл бұрын
Great content as usual, it's really hard to find react content at this level so it's highly appreciated. Great pattern, love the use of refs for this
@zlackbiro
@zlackbiro Жыл бұрын
This is the most insane video you made. This should be on npm as a library. 😁
@hikarukun5126
@hikarukun5126 Жыл бұрын
The only part I didn't understand was a pub/sub model and how it works, maybe because I have never used it before. I believe I will watch this episode a few more times and read articles about how this pattern works. Thanks a lot for such majestic content, I appreciate it as other fellows here.
@mikeks81
@mikeks81 Жыл бұрын
Really slick! Adopting this pattern immediately. Thanks for sharing!
@SergeyChebykin
@SergeyChebykin Жыл бұрын
Jack, thanks a lot for making really excellent educational videos! This one is especially important, given how easy it is to misuse React context and end up being deep under a lot of performance issues. Thank you!
@BHFJohnny
@BHFJohnny Жыл бұрын
I once faced this challenge: 1) I fetched data from API 2) Based on that data, I should have rendered a slider for each item from a list. I didn't know the count on build time, I only knew it on run time 3) Based on current values of all the sliders, I should have calculated sum and some validation boolean (like isOverLimit or something) My initial naive way was to pass down value and onChange props from a container component. As expected, didn't go well at all. Slider can easily fire 1000 change events per second. All sliders needed to rerender. I was laggy and terrible UX. Second approach was to hack it with throttle. Each slider would have its own local state and once in a while (let's say once per 250ms), onChange was fired and calculation synced. Worked better, but it still needed to rerender all sliders, though not that often. Hacky, ugly, not nice. I did a quick research and and found Recoil. I implemented runtime atomic state for each slider, two selectors for calculated value, everything worked perfectly, only things that really changed had to be rerendered. Tried with 1000 sliders just out of curiosity, worked flawlessly, slide back and forth on 4K display, no lags, blazing fast. This solution looks good in a way that it could replace my solution entirely, without Recoil needed to be installed at all. Really nice. I like this ref - subscriber - selector approach. It's clean, neat and elegant. No hacks needed.
@vakhtangnodadze4802
@vakhtangnodadze4802 Жыл бұрын
Awesome video Jack. Your videos are like goldmines.
@talatkuyuk6556
@talatkuyuk6556 Жыл бұрын
Your solution is awesome; you are great guy to explain this kind of structural videos, thanks again.
@tusharrai3644
@tusharrai3644 Жыл бұрын
Very sturdy implementation, just loved the approach and the way you explained. can't wait to Implement this fast context.
@BlurryBit
@BlurryBit Жыл бұрын
Lovely video! Concise, and very helpful!! Thank you Jack :)
@1235niki
@1235niki Жыл бұрын
Thanks for sharing this new pattern Jack. Really helpful.
@manuelpascual7063
@manuelpascual7063 Жыл бұрын
Jack, this is amazing content. I never thought about the idea to use this combination between context and useRef. You are such a huge inspiration 😊
@mikexcoder1508
@mikexcoder1508 Жыл бұрын
came here from Codecamp, awesome content. Subbed!
@loquek
@loquek Жыл бұрын
I really don't mind using Zustand and React-tracked for this (in-fact I love it), but nice still for a no-additional dependancies setup
@jherr
@jherr Жыл бұрын
Yeah, I use Zustand daily. But it is nice to have techniques like this in the back pocket.
@faviocabral2675
@faviocabral2675 Жыл бұрын
@@jherr Master Jack I can ask you something, what is better redux o context react Thanks.
@OleksandrDanylchenko2k
@OleksandrDanylchenko2k Жыл бұрын
Thanks 🙏 It's the clearest tutorial on how to implement the fast context
@ivanabadzhiev1214
@ivanabadzhiev1214 Жыл бұрын
Amazing, thank you Jack for all the value you provide with your videos
@Bookwala12
@Bookwala12 Жыл бұрын
Woah Jack, you are a magician and even after watching you so much, I still can’t wrap my head over some of your concepts.. humbling experience this video was.. I will come to it again a little later in life..
@oomettie
@oomettie Жыл бұрын
Thanks for the fantastic content! Love how you still get excited when your solution works (24:13). 😂 Even though you obviously prepped. Even though it's not unexpected. Keep up the great work!
@patrickkaipainen3301
@patrickkaipainen3301 Жыл бұрын
This is awesome. Been working on a dynamic form that can have any number of groups of several inputs each. The state for the entire thing lives in one provider. React.memo helps a bit with unnecessary renders, but this would work waaaay better.
@useeffect
@useeffect Жыл бұрын
Thank you Jack for really valuable React.js content on KZbin !
@fadfooood
@fadfooood Жыл бұрын
I will never do that but hey Jack now I understand what Zustand and other state managers do at a scale. Thanks!
@b3ncr0w
@b3ncr0w Жыл бұрын
That's exactly what I was looking for! Thank you so much : )
@ynonshoshan
@ynonshoshan Жыл бұрын
That was bloody amazing
@cpt.victor
@cpt.victor Жыл бұрын
Hey, awesome video! I have two questions that I couldn't find good answers for, which are: How should we compare using this pattern with contexts with the usage of zustand or jotai state management libs? What should we look for when comparing these kinds of options for our apps?
@corndoggydogdog
@corndoggydogdog Жыл бұрын
This is smashing, thank you so much Jack! 🔥🔥🔥🔥
@ryanle4059
@ryanle4059 Жыл бұрын
Thank you so much, Jack. I've tried this technique without using react context. I use closure for the store and it works perfectly fine. I don't know if any downside to this approach. Thank you again for sharing great quality content.
@jherr
@jherr Жыл бұрын
Downside to that is that you can't restrict it to a specific part of the tree as you can with context. That may not matter to you. Also, that approach is very similar to Zustand, so you might want to try that because it's of the shelf and well supported.
@shiyaamcodes7428
@shiyaamcodes7428 Жыл бұрын
I was looking for this exact thing for the past two days!!!! Glad I found this
@MrChernicharo
@MrChernicharo Жыл бұрын
Woooah! I couldn't stress enough how much I loved this video! Thank you Jack! 🥳
@javLG
@javLG Жыл бұрын
Thanks for this implementation, you're a beast Jack!
@FidelGuajardo
@FidelGuajardo Жыл бұрын
Jack this is a compliment. You are the developer version of Last Man Standing. I think you can be called "Last Dev Standing" !!!
@jherr
@jherr Жыл бұрын
Last Man Standing? There are a lot of devs around. :)
@doasalah
@doasalah Жыл бұрын
Hey Jack, I'm loving your channel. Please tell me, what do you use for autocomplete or make code suggestions?
@VoxyDev
@VoxyDev Жыл бұрын
Do you know any idea about the progress of the proposal of memorizing everything in React?
@jherr
@jherr Жыл бұрын
I haven't seen it. But I'm not opposed. I just think having to memoize everything ourselves isn't great DX.
@lorenzotomasdiez3325
@lorenzotomasdiez3325 Жыл бұрын
I just found out about your channel and it is impressive the way you explain. It's amazing.
@ozgursar5386
@ozgursar5386 Жыл бұрын
This tutorial is simply amazing. Thank you!
@ThugLifeModafocah
@ThugLifeModafocah Жыл бұрын
This was on another level. I really hate Typescript. I know its advantages, but I hate it nonetheless. But I'm kind of obligated to use it, and your video show me how to do something that I needed and have no knowledge how to do it. Thank you.
@motivateme2402
@motivateme2402 Жыл бұрын
Thank you Jack for the best content I've ever seen, you're a great and awesome guy, and You thought me a lot
@fahmijabbar1595
@fahmijabbar1595 Жыл бұрын
Absolute meat!!! Thank you for the tutorial Jack
@juliasetiawan9784
@juliasetiawan9784 Жыл бұрын
dang.. how did you come up with this? great stuff my man
@fotoflo
@fotoflo Жыл бұрын
Thanks Jack! Came for the context, stayed for the typescript!
@maherbenbaccar
@maherbenbaccar Жыл бұрын
thanks @jack you are my favorite professor and all your vedio is amazing and good thanks a lot
@jma42
@jma42 Жыл бұрын
This is actually something I really need trying to create my firs NPM package (just for myself for now and it makes me feel satisfied) but unfortunately im soo new to react that I don't really understand these nitty gritty stuff about useRefs and useCallbacks, but hopefully I'll be able to understand this soon!
@rogerscript
@rogerscript Жыл бұрын
Jack, you are my superhero!
@DinujayaRajakaruna
@DinujayaRajakaruna Жыл бұрын
Hey, I was wondering how would you use this createFastContext API when dealing with components that are in separate files to App.tsx. For example, lets say I want to share the state between Component A and Component B so I wrap these with Provider. How would Component A and Component B access the useStore() function? In your example these components live in the same file, so if they did not do you have to prop drill the useStore() function into component A and B?
@xromasik
@xromasik Жыл бұрын
I was wondering the same, any updates? I guess you can just put the createFunciton in separate file and then export useStore from it, this should work in theory
@agk2011
@agk2011 Жыл бұрын
Thank you so much for such an amazing video. This type of content is really inspiring.
@hanzladev
@hanzladev Жыл бұрын
I was surprised to see, after learning so much I haven't subscribed yet, what a shame... ;D Great leveling up, keep up the best work Thanks
@arogueotaku
@arogueotaku Жыл бұрын
This has to be one of the best react videos I have watched. +1 Subscriber
@coldboyvic
@coldboyvic 8 ай бұрын
This is one of the best tutorials on KZbin 🙌💯
@patrykkalinowski6979
@patrykkalinowski6979 8 ай бұрын
It was really good. Thanks a lot !
@rudi-batubara
@rudi-batubara Жыл бұрын
Best and clear explanations how to use useSyncExternalStore, thank you. I'am trying to implementing the fastDynamicContext to my current react-18-ssr project, but I'm stuck while trying to passing useStore to the deep child component, could you please to guide me?, thanks for advice 🙏
@현승재-h4f
@현승재-h4f Жыл бұрын
Thank you Jack, I really love this content I`m going to adjust this on my toy project now awsome!
@firstbiological6624
@firstbiological6624 Жыл бұрын
Also one quick question: My team and I have started implementing the fast context in our app. But there is one thing we can't solve for a few days regarding the fast context. Actually, our app allows users to undo/redo all types of actions (e.g. input changes, deleting and adding things). For each change in the store we provide a command, the command contains three things: execute (that's how the store should change), undo function, and redo function. So basically, we do something like: const set = useCallback((command: Command) => { // alter the state using the command stack.current.execute(command) // command here subscribers.current.forEach((callback) => callback()) }, []) [get, set, blablabla] But here is the problem. We need to pre-populate the state with data from the back end, but we can't do this using set, since a user will be able to undo or redo data from the back end, which is not what we want. By the way, I suppose that's a great idea for a video: How to implement undo/redo in a front-end application (maybe even with the fast context).
@jherr
@jherr Жыл бұрын
For an undo/redo system like that the usual pattern is insufficient. You need a way to set the state without adding an action. In addition you need a way to stack actions onto the head action to handle things like typing where you only complete the action after a 500ms delay in typing.
@firstbiological6624
@firstbiological6624 Жыл бұрын
@@jherr Thanks a lot!
@ricardozarrocaalegre7373
@ricardozarrocaalegre7373 5 ай бұрын
Wow, this is 30 minutes of pure learning... I was delving into ways to boost React's context performance for global states since I'm restricted from adding third-party libraries to a project I'm working on, and suddenly I stumbled upon this 🤯... Actually, just a few days ago, I watched Tanner's talk on creating a lite version of React Query (kzbin.info/www/bejne/b4TVepyop9OqoZIsi=C-4craWixIuQ_837), and he also employed the observer pattern. It seemed like the right approach to take (minus the overhead of handling async calls). I was pondering on the general way of how to do it, and suddenly I stumble upon your video, which not only has the entire solution already developed but also you explain it so cle arly and step by step that understanding it is very simple. Thanks for all this content you do!! One of the best for sure!!
Is the new React use hook a footgun?
22:20
Jack Herrington
Рет қаралды 60 М.
Mastering React Memo
26:56
Jack Herrington
Рет қаралды 135 М.
Inside Out 2: BABY JOY VS SHIN SONIC 3
00:19
AnythingAlexia
Рет қаралды 6 МЛН
отомстил?
00:56
История одного вокалиста
Рет қаралды 7 МЛН
Don't Use React Context!! Use This instead
13:34
CoderOne
Рет қаралды 28 М.
You're Doing React Hooks Wrong, Probably
20:11
Jack Herrington
Рет қаралды 64 М.
useCallback vs. useMemo
11:19
Jan Hesters
Рет қаралды 3,4 М.
This is the real purpose for react context
10:11
Web Dev Cody
Рет қаралды 22 М.
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Рет қаралды 85 М.
3 React Mistakes, 1 App Killer
14:00
Jack Herrington
Рет қаралды 115 М.
Mastering React Context: Do you NEED a state manager?
37:26
Jack Herrington
Рет қаралды 99 М.
Combining Zustand with React Query
20:24
Cosden Solutions
Рет қаралды 18 М.
Goodbye, useEffect - David Khourshid
29:59
BeJS
Рет қаралды 500 М.
Inside Out 2: BABY JOY VS SHIN SONIC 3
00:19
AnythingAlexia
Рет қаралды 6 МЛН