Тёмный

Mastering Typescript State Management using just React 

Jack Herrington
Подписаться 187 тыс.
Просмотров 15 тыс.
50% 1

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

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 81   
@king-manu2758
@king-manu2758 2 года назад
This channel is pure gold. I'm recommending this to everyone I know.
@chandruskc
@chandruskc 3 года назад
You are the only person who teach things about React in Typescript. Thank you!
@learningit2572
@learningit2572 2 года назад
I am beginer , and for me this videos so helpful! Thanks for your passion
@2penry2
@2penry2 3 года назад
Wow this is such a fantastic channel. So glad the RU-vid algorithm recommended it to me! Keep up the great work Jack!
@eleah2665
@eleah2665 3 года назад
Hi Jherr, you manage to cover things I'm most interested in and behind on. Thanks.
@RossOlsonDotCom
@RossOlsonDotCom 3 года назад
Great stuff. I particularly liked building it wrong... then stripping that out... while putting in the good stuff. Great context for 'context'.
@Shakeel714
@Shakeel714 3 года назад
Really really nice explanation of React hooks. Really helpful. Thanks so much, Jack.
@bythealphabet
@bythealphabet 3 года назад
good video, thank you Jack nice way to Convert into Typescript.
@usmaninuk
@usmaninuk 3 года назад
Best of the best on react typescript
@viveksharmapoudel1657
@viveksharmapoudel1657 3 года назад
great channel Sir...your videos are so underrated for they offer so much value yet so unknown among programmers.
@MarkDekkersLife
@MarkDekkersLife 3 года назад
Thanks, this is Glorious
@moretimeproductions
@moretimeproductions 2 года назад
Just amazing!
@wellington18m
@wellington18m 2 года назад
Hello there sir. I just found your channel and I really liked your content. Thanks very much for your teachings. You explain things very clearly. I was think if you could make a series on nextjs with typescript. Thanks a lot again!
@bojanchurlinov1385
@bojanchurlinov1385 3 года назад
Thanks Jack, awesome content... as usual :)
@sandycochrane7184
@sandycochrane7184 3 года назад
Since I started learning React with Typescript I generally find myself wanting to smash my laptop at least several times a day You are actually a hero for taking the time to explain this so clearly in a really logical progression through the complexity... and also additional thanks for delivering it with such a positive vibe. Surprisingly makes quite a difference in reducing the urge to throw a rage quit tantrum. I would describe this as the filet-mignon of React Typescript State Management tutorials
@jherr
@jherr 3 года назад
Haha, happy to provide the choicest cuts. :) Let me know if there are other topics you'd like to see covered. I may have something already, or make something new.
@mattmarkus4868
@mattmarkus4868 3 года назад
I agree with you on this channel and I'm in the same place with React/TS. I'm envious anytime I see examples in javascript, because they seem so much simpler and there's so much less noise/code. I find myself fighting with the TS compiler half the time. But I know there's a lot of value, I just haven't gotten versed enough in TS and React. I've definitely gotten a few ideas from this channel though.
@edgarcalderon4345
@edgarcalderon4345 2 года назад
Solid Content Jack, is there anyway to do useContext with using class based components rather than function based components?
@jherr
@jherr 2 года назад
I'm not sure, I haven't tried. I don't use class components. You can check this: reactjs.org/docs/context.html#classcontexttype
@Norfeldt
@Norfeldt 3 года назад
You put a bang after useContext because it can be null and mention quickly something about "coerced". Having seen this before in JS, is this a typescript thing and can you ref or eleborate on what it does?
@jherr
@jherr 3 года назад
It's a TS thing that says that this is guaranteed to be non-null.
@dot_fury
@dot_fury 3 года назад
Thanks for the great video, I learned a lot. I just have one question that was confusing me. At the end when you create the custom hook, in the helper methods (addTodo, etc.) You use `tl` ex. setTodos(tl => addTodo(tl, newTodo)); I noticed `tl` wasn't declared anywhere and assumed that useState set functions invoke with the state variable automatically? I didn't see anything in the React docs about that from what I can tell. Just has me scratching my head.
@jherr
@jherr 3 года назад
Right, in this case `tl` is the name of the parameter and this is an anonymous function declaration that takes that parameter and sends it on to addTodo. The first parameter is a todo-list so the name `tl`.
@dot_fury
@dot_fury 3 года назад
@@jherr Thanks!
@herbertpimentel
@herbertpimentel 3 года назад
Man, you rock!!!
@kafilnasdami2152
@kafilnasdami2152 3 года назад
Great material as always ! Presented in such a nice and entertaining way only an expert would know how to do . Thank you so much for this amazing content. I expected you in the end to remove the export keyword on your business methods ( add, remove, update, delete), did you forget to do it, or is there a specific reason you did not ? God bless you :)
@jherr
@jherr 3 года назад
Yep, I should have removed those and it slipped my mind.
@darian9508
@darian9508 3 года назад
tks a lot for react and typescript!!!
@jasonsebring3983
@jasonsebring3983 2 года назад
The only downside I see here is having to wrap multiple providers... over doing say pub/sub singleton approach. I do the latter but wrap it with useGlobalState type approach or HOC. This was a well done presentation.
@alexandrepedroza9217
@alexandrepedroza9217 2 года назад
This sounds interesting, could you elaborate a bit or provide an example of what you mean?
@samfreeman9330
@samfreeman9330 Год назад
Hey! Thank you for this tutorial. I am. *just* learning TS and therefore am struggling to troubleshoot. I am console logging the current todos and it seems like done isn't changing to true for me. Any thoughts?
@mansamusa559
@mansamusa559 3 года назад
Awesome thanks alot
@georgy2763
@georgy2763 2 года назад
I am beginner in typescript, but I found this lecture (especially the part with custom hooks) to be quite difficult to understand. I can see that the material is top notch, I just wish, it would be more “accessible” to beginners. Like explaining why we add callback functions to methods in our return statement, etc.
@georgy2763
@georgy2763 2 года назад
I think I figured out the cb part)
@mattmarkus4868
@mattmarkus4868 3 года назад
I really enjoyed your videos on custom hooks and using context! Your channel is unique and goes beyond the norm, which is much appreciated. But I found myself wishing that you had used an item that's a little bigger than a todo (eg, an employee, or customer - something with more fields). I ask because I have a project I'm working on that has a screen with multiple tabs and item data on each one- and I really want to find an elegant solution to the state part of it. My screen only has 7 fields at the moment and the change handlers on the text fields alone are making things way too busy for one file (ie, prop drilling). Can you put the change handlers that set new state on every keystroke in a different file/hook and import those instead of having them in the file that renders the input fields? I know that something similar to your custom hooks with context must be the answer, but I can't quite map the todo example to mine.
@jherr
@jherr 3 года назад
Early on in my career I had a job where I needed to build a single dialog with 8 tabs with interconnected fields. What I ended up doing was creating a "view model" that mapped 1:1 with the controls and it then translated its own state to what the backend needed. I then made extensive use of the observer pattern to connect the controls the view model. Technologies have changed, but I think the approach is solid. If you use something like Valtio or MobX to manage the view model it should scale up to the size you need.
@robovirtuoso1354
@robovirtuoso1354 3 года назад
I recently embarked on a no-libraries React state management in TypeScript, actually inspired by this video. But... few days ago I discovered something in Hacker News.... a lib aptly called "Simpler State", so far it's looking super simple to me. My library-less React TS app suddenly got shorter, feels like Context API without providers.
@jherr
@jherr 3 года назад
It looks good. I'm not a huge fan of the `entity.use()` but there appears to be a `useEntity` as well. Slightly concerning to me is that the library is actually written in JS and it's just the types file that's in TS. Not sure why that's the case. I think it would be less error prone to also write the library in TS. But that's just because nowadays I write everything in TS, even the simple stuff. This kinda reminds me of Daishi Kato's `react-hooks-global-state` but with a bit more to it. I'm not sure in Daishi's case you can set the state outside of a React context but I think you can with this one, which is good.
@robovirtuoso1354
@robovirtuoso1354 3 года назад
@@jherr Funny you mentioned it, I much preferred the useEntity() alternative to the example entity.use() too. And as for JS source, i agree TS is more readable. But i dont mind it too much cos even my TS app barely has explicit typings anyway... so as long as type inference works im good with that.
@jherr
@jherr 3 года назад
@@robovirtuoso1354 Yeah, the TS stuff comes through because of the types, I'd just rather those types were auto-generated from the source. I actually put a trivial PR into the repo because the definition for `resetAll` was duplicated, and that wouldn't have happened if the types were generated. And there is no way for the types to go out of sync as well. It's funny, there actually is a lot of extra stuff in there around metadata and I'm not sure what that's about. It's all undocumented.
@jherr
@jherr 3 года назад
@@robovirtuoso1354 Totally agree about `useEntity`. If you want to do the React thing then do `useEntity` and call it a day. `entity.use()` is just gonna look odd to React folx.
@robovirtuoso1354
@robovirtuoso1354 3 года назад
@@jherr The extra stuff is probably traces of a secret plan for world domination lol.
@techhguy
@techhguy 3 года назад
Hey Jack! Awesome Content as always! I noticed that the store did not accept the Context Provider when the file name was store.ts but accepted it after it was renamed to tsx. What is the difference between ts and tsx files? Are there things I should keep in mind while naming them to ts or tsx files?
@jherr
@jherr 3 года назад
TS files do not allow for the JSX syntax. If you want to do the "embed the HTML in the code" thing ;) then you have to do .tsx.
@techhguy
@techhguy 3 года назад
@@jherrmakes total sense. Thank you for clearing out my confusion and the quick reply!
@shivashankar6043
@shivashankar6043 3 года назад
Hey jack please do more video with ts
@jhonatanmendes2494
@jhonatanmendes2494 3 года назад
Reeally good
@rangabharath4253
@rangabharath4253 3 года назад
awesome
@Norfeldt
@Norfeldt 3 года назад
Really good video BTW
@Rajibahmed
@Rajibahmed 3 года назад
I like the pattern you created with interpolated type / guessed typed. Is it a common thing you seen in many project. Or you came up with this idea. Pretty neat though :) I struggle with react with one thing. It creates ton of anti-pattern, biggest of the all is redux :) big global var anyone can write or read from :). The context pattern I am not 100% convinced about either. I can not put my fingre on it but it feels this is not the way :). React for me is functions calling functions, functional/currying library. It has elegance when you think like that, but breaks down when they start injecting stuff. I guess real world problem can not be solved by Haskell (lolzzz) BTW :) as usual great stuff man !
@jherr
@jherr 3 года назад
On the plus side, as we look at a number of state managers in this series some of them do not use context to share state, so you might find something you like.
@dealloc
@dealloc 3 года назад
You've got some misconceptions about Redux. It doesn't act like a "global var" because it is immutable and can only be updated through dispatching actions and run reducers to decide the new state. It's one way only, meaning you won't run into the problems that a "global var" has, such as race conditions. This is how state is often handled in functional programming languages. As for React Context, it is simply just a dependency injection mechanism (not state management). Rather than drilling state deep down in your tree manually resulting in many dependencies, Context provides a mechanism that allows you to access top level state with less friction, while preserving the single source of truth.
@Rajibahmed
@Rajibahmed 3 года назад
@@dealloc thanks :) for the insights
@axe-z8316
@axe-z8316 3 года назад
You might want to be clearer / more precise on the typescript specific stuff ( the reasons behind decisions) , exporting the useSate from the store and not from the App for instance, the returnType Tupple VS export type TodosSetter = React.Dispatch. btw, i'm not the thumb down guy ;)
@jherr
@jherr 3 года назад
Good point! I'll double down on that on the Friday livestream. (No worries if you were the "thumbs down guy". :))
@axe-z8316
@axe-z8316 3 года назад
@@jherr I m really not !! ;)
@ericzorn3735
@ericzorn3735 3 года назад
Hey Jack, what is your opinion on state machines?
@jherr
@jherr 3 года назад
I think they are fantastic when you have a system with discrete states. I've done some videos on XState and it's great stuff. I wrote a GraphQL subscriptions based game that used XState for game management and it was AWESOME. The issue I have with it is that the current tools are an either/or, it's like, everything is in the state machine, or everything is not in the state machine. Which is why I think what Daishi Kato has going on with doing an optional XState integration into Jotai is very compelling. You can have one piece of state modeled as a state machine, while other pieces of state are get/set kinds of things un-related to the state machine. Once that integration is done I look forward to doing some videos on it. What's your take? Should I do XState as part of this series? I think I'd have to go beyond Todos though since they don't really require a state machine.
@ericzorn3735
@ericzorn3735 3 года назад
@@jherr thank you for the very thoughtful reply. I have to scroll back and watch your GraphQL And XState series. From my experience using XState, I agree that with encapsulatesd state that is highly dependent upon one another, it is probably best with a state machine. Otherwise, libraries like those from Daishi Kato, or others (redux/toolkit, mobx, recoil), are probably best with the getter/setter approach. I am a heavy flux pattern enthusiast, however, having to handle asynchronous actions with custom middleware is a bit bloated and heavyweight. Therefore, framework agnostic libraries that sit outside of react context are appealing. They are light weight, async capable, and much more performant. I just think they need time to catch on. Engineers in my opinion are overly used to frameworks like Redux and MobX for scalability. Plus, this video demonstrates best context practices, but many engineers probably don’t utilize context efficiently (waiting for the new selector hook). I know this is a very long post, but I definitely would love to have some videos within the series on X State and a comparison to alternatives. It can put things into perspective for your app. Thank you for the great content as always! Sincerely, Eric Zorn
@jherr
@jherr 3 года назад
@@ericzorn3735 Now that you bring it up I really do want to integrated XState into this, but the Todo example just isn't complex enough. So if you have some ideas for that let me know either here, or on Twitter (@jherr) or on the Discord server.
@ericzorn3735
@ericzorn3735 3 года назад
@@jherr I can definitely keep the convo going on Twitter so that I don’t clutter the comment section. Definitely thinking of a good alternative example
@Norfeldt
@Norfeldt 3 года назад
I really like that you moved the "set" part when using useState to the end of the variable instead of in the front (the type should perhaps be named likewise. I'm considering to be inspired and use a good practice to write it like this in the future const [todoGet, todoSet] = useState(null)
@j3bb9z
@j3bb9z 3 года назад
Please DON'T! It's a generally accepted convention (not just in React!) to name setting functions as setSomething. Why would you do it the other way around?! Name like 'todoSet' would suggest not a function but 'a set (collection) of todos'. Also, the first element of the array returned from the useState hook is not a function, but the state itself. Naming it todoGet would be just plainly wrong. Jack, I appreciate what you're doing, and I'm sorry to say this... but in this case, as an educator, I think you should have known better. Keep up the good stuff though!
@lllllllllIIIIIIIIIIl
@lllllllllIIIIIIIIIIl 3 года назад
@@j3bb9z I would refuse to work with anyone who inverted the `setSomething` convention.
@j3bb9z
@j3bb9z 3 года назад
@@lllllllllIIIIIIIIIIl Ah, sorry, I misread your comment when I replied the first time. I've read it as "invented" instead of "inverted". I fully agree. :)
@AntonioLopez8888
@AntonioLopez8888 3 года назад
Kung fu modern react
@piotr5014
@piotr5014 3 года назад
zajebiste
@lucaszapico926
@lucaszapico926 Год назад
The useState typing pattern at 5:45 is soo clean. 🥹 Thank you soo much. Drilling "useState" and importing "Dispatch" was making my code gross. I was getting confused and frustrated. Thank you very much for these videos.
Далее
Mastering Typescript State Management using Redux
28:09
Mastering React Context: Do you NEED a state manager?
37:26
You're Doing React Hooks Wrong, Probably
20:11
Просмотров 64 тыс.
Mastering async code with Typescript and Javascript
39:01
Context API in react | get the concept
29:00
Просмотров 63 тыс.
Mastering React's useEffect
25:20
Просмотров 175 тыс.
Todo List in ReactJS using TypeScript Tutorial
38:57
Просмотров 98 тыс.
Common React Mistakes: useEffect - Part 1
19:57
Просмотров 46 тыс.
Typescript Generics Tutorial
21:56
Просмотров 219 тыс.
State Managers Are Making Your Code Worse In React
13:33