Introduction to MobX & React in 2020

  Рет қаралды 66,223

Leigh Halliday

Leigh Halliday

Күн бұрын

Пікірлер: 273
@waffstacks
@waffstacks 4 жыл бұрын
Thank you Leigh! This has been the easiest tutorial to follow, better than the official documents!
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you very much, David, I appreciate it!
@motionsiren
@motionsiren 4 жыл бұрын
Hey Leigh. This video was my entrypoint. The Ten minute introduction is perfectly fitting, but I was failing to hook in and feel the flow until you took us through this minimal high-level overview. Thank you!
@leighhalliday
@leighhalliday 4 жыл бұрын
Nice :D Thanks Ben, I appreciate the kind words! Glad the vid was able to help.
@ticos.thepsourinthone9150
@ticos.thepsourinthone9150 4 жыл бұрын
Thank you so much for making this easy-to-follow tutorial, Leigh! I was struggling to find a React + MobX tutorial that was as clear and concise as yours! The speed with which you present, the injection of the "why" we do this, the memorable example of 'bugs', and the numerous 'recaps' are like food for my brain, Leigh! YOU. ARE. AWESOME.
@leighhalliday
@leighhalliday 4 жыл бұрын
Nice! I'm glad it was able to help! Thanks for saying hi and the kind words, Tico!
@KirkQuesnelle
@KirkQuesnelle 3 жыл бұрын
This was such a good introduction. You have a very good teaching style. I'm able to get up and running now because of the work you put in. This is so greatly appreciated! I was hoping you had a course on it. I'm a subscriber now at the very least
@leighhalliday
@leighhalliday 3 жыл бұрын
Hey Kirk! I do have a course... but it doesn't use MobX unfortunately... we just use useState to manage things :) It's available at next.leighhalliday.com
@stillbald5827
@stillbald5827 4 жыл бұрын
Thank you! I think I finally understand MobX. Now I'm off to try and it, and realize that I don't understand it at all!
@leighhalliday
@leighhalliday 4 жыл бұрын
Haha... don't stress! You don't even have to use MobX... you can accomplish most things with normal state in react and context without any issues. I plan to push out a MobX 6 video shortly... but the truth is that personally I don't really use MobX/Redux any more ever since hooks came out.
@Sukis666
@Sukis666 4 жыл бұрын
Hey man! I've previously only programmed C# for games and have a tough time with the super quickly advancing web development world. I needed state management for an app and failed hard with Redux. After watching this I got state management sorted out with MobX instead. Thanks, you are a lifesaver :) !
@leighhalliday
@leighhalliday 4 жыл бұрын
Nice! Glad I could help :) Web dev is the sort of thing where if you look away for a few minutes, you feel years behind... but in a sense, who cares what you're using so long as you're shipping things for users. Doesn't matter if it is the latest or greatest state management library.
@TheJrw456
@TheJrw456 2 жыл бұрын
super helpful! I finally understand. Also, in 2022 now, useLocalStore is now depreciated and there are saying that useLocalObservable is the way to go.
@sarfarazalam6077
@sarfarazalam6077 3 жыл бұрын
Very easy to follow & great simple example to follow.
@romimaximus
@romimaximus 3 жыл бұрын
Wow !! Mobx is a LOT simpler than freaking Redux !! i absolute loved it !! thankx for sharing it.!!😁👍
@abessesmahi4888
@abessesmahi4888 4 жыл бұрын
It will be nice to update all your old tutorials. Thank you so much for this tutorial.
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Abesse! I'll try to do this for my popular ones... maybe not all of them though, I think I am over 80 videos now :D
@les2997
@les2997 5 жыл бұрын
Thanks for the video. I like how MobX turns getters into computed properties. If I didn't use MobX and wanted to have a similar functionality, I'd have to use useMemo and provide a list of dependencies. The MobX approach looks a lot easier when there is a lot of computed/derived data.
@leighhalliday
@leighhalliday 5 жыл бұрын
Thanks for watching and replying Les! Glad you enjoyed the video.
@philippeclavier4190
@philippeclavier4190 3 жыл бұрын
Loved it! Completely clear and easy to follow
@leighhalliday
@leighhalliday 3 жыл бұрын
Thanks Philippe! I have an even newer (AND BETTER muahaha) video to check out on MobX if interested: kzbin.info/www/bejne/jYK0omSHl76fd9k
@philippeclavier4190
@philippeclavier4190 3 жыл бұрын
@@leighhalliday I have seen it! Will watch it soon
@danielnadar75
@danielnadar75 2 жыл бұрын
Awesome and Quick ❤️
@plaxdan
@plaxdan 4 жыл бұрын
Excellent job. Great cadence and clear concise examples.
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks Daniel, I appreciate it!
@ignaciodelamadrid
@ignaciodelamadrid 4 жыл бұрын
Awesome work Leigh!
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you Ignacio!!
@karmanw5678
@karmanw5678 4 жыл бұрын
Thanks for this great video :) So happy to see an SLC grad doing such great amazing things!!!!
@leighhalliday
@leighhalliday 4 жыл бұрын
No prob, Karman!! Loved my time at St. Lawrence. Scott (twitter.com/svinkle) was in my class/year and is doing amazing things too... sadly haven't kept in touch with others (graduated 15+ years ago now).
@karmanw5678
@karmanw5678 4 жыл бұрын
@@leighhalliday Thanks, I'll follow him too :) Time really does fly! Janis and Colin Banger are still teaching us. Still a lot of mainframe haha... Donna is retiring this year!
@calistusobeke7520
@calistusobeke7520 2 жыл бұрын
Nice job. thanks for sharing. LOVE FROM NIGERIA
@leighhalliday
@leighhalliday 2 жыл бұрын
Thanks Calistus, love from Canada!
@onmakaev
@onmakaev 4 жыл бұрын
Красапет!)) That means you did a good job. Thanks!
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you very much, Emil!!
@iqwebserve3973
@iqwebserve3973 4 жыл бұрын
Great tutorial Leigh, thanks.
@leighhalliday
@leighhalliday 4 жыл бұрын
You're very welcome!
@jumavipe
@jumavipe 4 жыл бұрын
Hello Leigh, do you have recommendations to File structure? or how could we use this having the components in diferente files and the provider in diferent files? I got the concept but if you have a repo that you can share with us in wich they use the storeProvider and the components in separate files would be so much help!
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Jumavipe! That's a good question and I don't think I've thought about it enough to have a really good answer. If I only had 1 store, I'd probably put it in a `src/utils/store.js` file, and if there were multiple stores, maybe I'd have a folder for them all. I've seen "atomic design" structure work well in React: cheesecakelabs.com/blog/rethinking-atomic-design-react-projects/ I haven't built many large React applications myself... at work I focus on backend Ruby, so I think that's why I don't have a great answer :)
@lordfresh
@lordfresh 3 жыл бұрын
What a great explanation! Thanks!
@leighhalliday
@leighhalliday 3 жыл бұрын
Glad you enjoyed it!
@嘴吸杯子
@嘴吸杯子 5 жыл бұрын
Thank u for the video. I want to know what is right way to handle with side effects, something like fetch?
@leighhalliday
@leighhalliday 5 жыл бұрын
Good question! I **think** you can just do them inside store functions (actions)... give it a try and let me know! Here's a video I made on this previously, but it was using a class based store and I think things have changed a bit since then: kzbin.info/www/bejne/qGPVepikatV4mLM
@vitaliano01
@vitaliano01 4 жыл бұрын
Thanks for the update video and the intro to Mobx with React
@leighhalliday
@leighhalliday 4 жыл бұрын
Glad you enjoyed it, Paul! Thanks for saying hi :)
@DjLeonSKennedy
@DjLeonSKennedy 4 жыл бұрын
That was perfect, cool video, many thanks bro!
@leighhalliday
@leighhalliday 4 жыл бұрын
No problem!! Glad you enjoyed it :)
@jonwatte4293
@jonwatte4293 2 жыл бұрын
It's 2022. This feels twenty web years old! :-)
@edwinwong9033
@edwinwong9033 4 жыл бұрын
Interesting! MobX + useContext. combination are working perfectly.
@leighhalliday
@leighhalliday 4 жыл бұрын
:D Yea, pretty cool eh? I've always been a big fan of MobX!
@alexwong1771
@alexwong1771 3 жыл бұрын
So the StoreContext instance should be imported in any component which wanna access the store, right?
@topogigio10
@topogigio10 4 жыл бұрын
Muchas gracias por tus videos! Saludos desde Argentina
@leighhalliday
@leighhalliday 4 жыл бұрын
Gracias por el apoyo Ignacio :) Saludos desde Canada!
@leap8351
@leap8351 4 жыл бұрын
This guy has the best analogies
@leighhalliday
@leighhalliday 4 жыл бұрын
Haha thank you. Never been so proud of being this guy :D
@Turtlesnakemoose
@Turtlesnakemoose 3 жыл бұрын
Thanks for this, very helpful.
@leighhalliday
@leighhalliday 3 жыл бұрын
Thanks Michael! I actually recently published an updated version if you're interested kzbin.info/www/bejne/jYK0omSHl76fd9k
@kylenakamura4353
@kylenakamura4353 4 жыл бұрын
What's the best way to persist the LocalStore on page refreshes, and more importantly, up the Component tree to access that store from another page or component? For example, how can I have index.js print the value stored in `store.bugsCount`?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Kyle! What about setting up a useEffect hook that detects when the store changes and writes that data to local storage? Then when the page loads, you set its initial value to whatever is in local storage if anything is there.
@_Yolandi
@_Yolandi 5 жыл бұрын
thank you for redoing this video! you are a real bro!
@leighhalliday
@leighhalliday 5 жыл бұрын
Thank you, Yolandi! A lot had changed in MobX land since the first one.
@damonwu9658
@damonwu9658 4 жыл бұрын
Thanks Leigh, good stuff
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks, Damon! :D
@robbieg25
@robbieg25 5 жыл бұрын
Super clear and helpful video. Thank you.
@leighhalliday
@leighhalliday 5 жыл бұрын
Nice :D Thank you, Robbie! Glad you enjoyed it.
@muhammedabdurahman6026
@muhammedabdurahman6026 2 жыл бұрын
can we put observable above all component
@timbabs1
@timbabs1 3 жыл бұрын
what theme are you using for vs code?, I quite like it
@hgohgo12
@hgohgo12 3 жыл бұрын
Hi Leigh Thanks for the nice tutorial. How would you do it with the latest version of mobx ?
@leighhalliday
@leighhalliday 3 жыл бұрын
Hey HGO! Honestly not sure! I haven't used MobX since I made this past video... I plan to do a 2021 version probably within the next few weeks.
@rudeadyet1992
@rudeadyet1992 4 жыл бұрын
Nice and clean! Thank you 🙏
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you Sarthak!!
@kieranosgood3297
@kieranosgood3297 4 жыл бұрын
In terms of typescript, it complains that object is possibly null if I do a React.createContext() without a default state, is there a best practice for defining a default state without having to redeclare everything I declare in the useLocalStore, or how best to handle/set this up? (p.s. great vid - realised when I watched this a few weeks back I subbed but didnt turn the bell notifications on, will defo be following your stuff dude) edit: I created a type for the store and in the create context I did React.createContext({} as StoreType) - Seems to have worked, hopefully that's the ideal way
@leighhalliday
@leighhalliday 4 жыл бұрын
Cool, glad you got it figured out Kieran! I'm not an expert at TypeScript, so I don't think I have too much of an opinion on it, other than I'm glad you got it working. Thanks for your support :)
@cnascimentobr
@cnascimentobr 4 жыл бұрын
@@leighhalliday Thanks for the video! I've made a repo based in your video but using TypeScript just for training. Check it here: github.com/cbfn/pomodx
@leighhalliday
@leighhalliday 4 жыл бұрын
Awesome, thanks for sharing, Christian!
@cnascimentobr
@cnascimentobr 4 жыл бұрын
@@leighhalliday ;-)
@murraybauer3535
@murraybauer3535 4 жыл бұрын
Nice 2020 'update' for Mobx. Would like to see a vue.js video using Mobx with the new composition API.
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Murray! I've actually never used Vue.js before, so I don't think that's coming any time soon haha!
@jacoblu9407
@jacoblu9407 4 жыл бұрын
Great Video. Very clear
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you Jacob!
@frostyghostman6430
@frostyghostman6430 4 жыл бұрын
Always lovin the content mate, any chance on an updated async mobx tutorial to complement this vid??
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Frosty! I see that version 6 is being worked on now... I may do a new video when it has been released and I'll try to cover async actions!
@frostyghostman6430
@frostyghostman6430 4 жыл бұрын
@@leighhalliday fantastic mate lookin forward to it
@BlademanZX
@BlademanZX 4 жыл бұрын
So if I'm understanding correctly (making this comment at 4:45 in the vid), if I wanted my store to be in a separate file I would put Const StoreContext ... Const StoreProvider ... those functions, (so lines 4-14) in a separate file and export, then in App or wherever I would import that component and use it as a wrapper for all my child components?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Kizuna! Yea, you could totally put that into a separate file, export it, and import it wherever you need it. I'd probably use your StoreProvider within the App or a high level component so that the state is available to all of your application... then you can just import the context into whatever child component that needs to read the state.
@BlademanZX
@BlademanZX 4 жыл бұрын
@@leighhalliday I don't really understand the importing the context part - also I don't understand why some of this is necessary, other vids I've seen as well as the MobX docs seem to suggest I just need to import MobX (Observer or Observable) and set each value in state to an observable and then the components which need to update based off of that to be an observer
@BlademanZX
@BlademanZX 4 жыл бұрын
@@leighhalliday Can you explain how importing the context into other child components would work please?
@mrkhoros
@mrkhoros 4 жыл бұрын
Correct me if I am wrong but everytime state updates the component reload. If this is the case, won't wrapping everything in context make unnecessary reloads and mess some stuff up ?
@leighhalliday
@leighhalliday 4 жыл бұрын
If that becomes an issue you could look into this technique. But otherwise I wouldn't worry too much!! kzbin.info/www/bejne/eXWqc4eggqd9sMk
@CkerCky
@CkerCky 4 жыл бұрын
Awesome video! Btw, which font are you using in vscode?
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks! "Code Lens Font Family"
@abonoah-3495
@abonoah-3495 4 жыл бұрын
Awesome! Thanks, you made my day.
@leighhalliday
@leighhalliday 4 жыл бұрын
:) Glad you enjoyed it, Muhammad!
@jumavipe
@jumavipe 4 жыл бұрын
hello there again! haha I have another question! is it really neccesary to use mobX considering the new context and hooks features are supposedly supposed to replace redux and mob-x since it helps manage the state because before them you couldn't manage it as easily
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Jumavipe! No, it isn't necessary... you can use useState, useContext, useReducer, useEffect, etc... and avoid using MobX or Redux... I'd honestly just go with whatever you're most comfortable with or you enjoy using the most.
@louisdedecker4807
@louisdedecker4807 4 жыл бұрын
Thanks, this was a good introduction !
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you Louis! Glad you enjoyed it.
@stevereid636
@stevereid636 5 жыл бұрын
Thank for the intro. You made look really simple.
@leighhalliday
@leighhalliday 5 жыл бұрын
Thank you, Steve :)
@blissofkundalini
@blissofkundalini 3 жыл бұрын
Ok fine, but how do I use it when splitting components into individual files?
@AmberCheaaa
@AmberCheaaa 4 жыл бұрын
What auto formatter is used at 8:45?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey A W! Most likely prettier... that's the only one I use.
@SavijCoder
@SavijCoder 5 жыл бұрын
Great video for using react with functional components. Question - If I wanted to use multiple stores, what would that look like? Multiple contexts or just an array of stores as the value? What's the best approach? Thanks again!
@SavijCoder
@SavijCoder 5 жыл бұрын
weird place to put code, in youtube comments, but I solved it like this (typescript) export const StoreProvider = ({ children }) => { const store = useLocalStore(() => ({ loginStore: { email: ['neil.peart@rush.yyz'] }, applicationStore: { firstName: 'neil', lastName: 'peart' } })) as StoreType; return ( {children} ); };
@leighhalliday
@leighhalliday 5 жыл бұрын
Thanks, Jeff! Check out this documentation to see if it points you in the right direction for dealing with multiple stores: mobx-react.js.org/recipes-context#multiple-global-stores
@Dron008
@Dron008 3 жыл бұрын
What about data fetching? Where it happens and how to initiate it? UseEffect or something high level?
@leighhalliday
@leighhalliday 3 жыл бұрын
Hmm, good question. The truth is that I typically wouldn't fetch data inside of MobX. I like to separate my app state from external data, and I'd use something like react-query, swr, or apollo.
@Dron008
@Dron008 3 жыл бұрын
@@leighhalliday I see. We use Redux/sagas with api level and mainly class components and want to get rid of Redux boilerplate. So it looks like MobX is not enough and we need additionally a separate data cache library.
@kmylodarkstar2253
@kmylodarkstar2253 4 жыл бұрын
Eres muy chevere, I like to practice english watching this. Very useful, I'm newbie with observables, looks pretty easy in react with mobx, than RxJs
@leighhalliday
@leighhalliday 4 жыл бұрын
Eres muy chevere tambien Kmylo! I haven't tried RxJs yet... should I?
@kmylodarkstar2253
@kmylodarkstar2253 3 жыл бұрын
@@leighhalliday Hi dude, yes I think is a bit more complex than mobx, it's what I feel at high level. But is a great tool with many features. I saw this old conference and was really inspiring to check this stack.
@pauek
@pauek 5 жыл бұрын
Excellent video!
@leighhalliday
@leighhalliday 5 жыл бұрын
Gracias Pau!!
@CoryTheSimmons
@CoryTheSimmons 5 жыл бұрын
Have you used easy-peasy yet? The guy who made MobX made Immer (and then use-immer). use-immer is a dependency of easy-peasy, and easy-peasy gives you Redux Devtools. It's like mobx-state-tree. A bit of mutability + Redux Devtools. Alternatively, I've been considering just throwing out all 3rd party stuff and just using useReducer locally on components, and alongside useContext for global state. I need to go back and watch your xState videos. David K. Piano is an IRC legend and I'm curious what state stuff he cooked up.
@ftnsco
@ftnsco 5 жыл бұрын
Cory, this is awesome man. Thank you. I'm working on a project where I'm using useReducer with useContext but, I really like how intuitive and simple easy-peasy looks. Can't wait to try it out.
@terrysahaidak
@terrysahaidak 5 жыл бұрын
No, easy-peasy isn't like mobx-stat-tree. It's more like redux on steroids with all its problems. MST allows you to navigate through your tree and operate on references to models, since it isn't using the immutable data structures. You can safely point a reference as a property of your model and be safe it won't change in the future until you destroy it by yourself. You can connect ReduxDevtools to MST as well as Reactotron to track all the changes. But still it's using mobx under the hood. And the main point of mobx - you will have the best performance out of the box, because of how observer (useObserver) works under the hood. Since mobx offers you mutable style of programming, you can mutate any prop and if you wrap your components with observer/useObserver, if will figure out where did you use it and rerender ONLY that component even deep in the tree. With useReducer and useContext you'll have redux withhout redux. You will still HAVE to use reselect and do many optimization such as shouldComponentUpdate/memo and you won't probably get the same performance mobx offers to you for free. Also, Mobx/MST is TypeScript friendly. You can check out mobx-keystone too as it aims to fix all the problems you migh have with mobx-state-tree and typescript (its written by MST TS maintainer).
@CoryTheSimmons
@CoryTheSimmons 5 жыл бұрын
@@terrysahaidak Thanks for the thoughtful reply. I didn't realize MobX was faster than something like Immer. Now I'm very interested in state management perfs. Do you happen to know the fastest? Also, why do you say easy-peasy is "more like redux on steroids with all its problems"? What problems specifically?
@terrysahaidak
@terrysahaidak 5 жыл бұрын
@@CoryTheSimmons mobx and immer are not comparable, since they are doing different things. immer is mostly a tool to allow you to easily write reducers in mutable way (in context of redux or any other flux-like lib), mobx is about observables and observers (components which tracks usage of observables and "subscribes" (because they don't really subscribe) for changes automaticaly. But if you choose mobx, you will have the best available performance yet in a big application (benchmarks are showing nothing) without any work on optimizing your components. Tte othres, those with immutable data structures, all have same problems in context of react: when you update a object deep in a tree, you create new objects/arrays for all of its ancestors (just look on how you use all those spread operators in redux or try to update an object deep in a tree via immer), so now every component will receive updated props (those ancestors) deep-deep to the actual component which uses that exact object you've just updated. You can optimize it using reselect, but there are still cases where you won't. Mobx don't have that problem at all. You can watch that talk in order to learn how mobx works and you'll realize why it's so fast: kzbin.info/www/bejne/hpC6on6QrdWLbsk
@CoryTheSimmons
@CoryTheSimmons 5 жыл бұрын
@@terrysahaidak Ah, I thought Redux might have been doing some normalizing, but apparently it isn't unless you use Reselect. Sigh. And Immer/easy-peasy don't. I tend to use Apollo, which I believe uses selectors on whatever data it queries, so using Immer/etc. on components didn't seem to slow anything down. I've definitely used Mobx on a couple huge projects before, and was on the fence about the API (not a fan of classes). The more I work on projects though, the more I'm concerned about perf, so yeah, I'll check out that vid you linked and probably give Mobx another try. Leigh, this kind of selector/perf stuff in the state ecosystem would make a really valuable playlist.
@armenstepanyan2954
@armenstepanyan2954 3 жыл бұрын
great video!
@jackzeelzadirgarciavalleci1457
@jackzeelzadirgarciavalleci1457 5 жыл бұрын
Really like your videos!
@leighhalliday
@leighhalliday 5 жыл бұрын
Thank you very much, jackzeel!
@mominahmad5575
@mominahmad5575 3 жыл бұрын
By pushing in the array, you are not changing the reference, then how react is able to rerender?
@leighhalliday
@leighhalliday 3 жыл бұрын
MobX handles this, they use something called proxies to detect when you mutate an array or object and this in turn triggers a render
@mominahmad5575
@mominahmad5575 3 жыл бұрын
@@leighhalliday Thanks a lot for clarification.
@terrysahaidak
@terrysahaidak 5 жыл бұрын
Nice video! Love it. Several notes for future readers: 1. It's probably better to use `observer` instead of `useObserver`. It will allow mobx to track all the properties you're accesing in your component, not only in the "render" part of it. It uses `useObserver` under the hood, but just looks a bit nicer. github.com/mobxjs/mobx-react#observercomponentclass 2. The `useLocalStore` is a hook, so you should use it only inside a component.
@Kanexxable
@Kanexxable 5 жыл бұрын
Do you prefer to use a root Store when using mobx or just importing different stores and can you use a root Store with mobx state tree
@terrysahaidak
@terrysahaidak 5 жыл бұрын
@@Kanexxable since I'm using mobx-state-tree, it won't work without a root store, but for mobx it's ok to have several stores, without a root one, you can even create a hook for each, like `useAuthStore`, `useUsersStore` etc.
@leighhalliday
@leighhalliday 5 жыл бұрын
Thanks Terry! All good points :)
@DalerAsrorov
@DalerAsrorov 4 жыл бұрын
@@terrysahaidak separation of concerns within the store is awesome. I do not want components that are handling user authentication, for example, to re-render if I am just changing data in the the bug list
@chulkim3556
@chulkim3556 4 жыл бұрын
Great introduction!! Thank you!!
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks Chul Kim! Glad you enjoyed it :)
@zakircinjarevic3115
@zakircinjarevic3115 5 жыл бұрын
why didnt you make a new folder and separate the concerns ? This way its harder for me to do it myself
@leighhalliday
@leighhalliday 5 жыл бұрын
Hey! I might do that in a real app that will have a larger store, but it's easier for a small demo on video to keep things in a single file... less jumping back and forth. That said, I'm not against having multiple related components in a single file.
@solelan1094
@solelan1094 4 жыл бұрын
@@leighhalliday for me it was harder this way, because I cant separate it now, Im not sure what vars needs to go where
@okoiful
@okoiful 4 жыл бұрын
How would you pass something like store.bugs as props to make the components reusable... otherways they are coupled to the data. thanks!
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Giorgio! How about just separating it into 2 components... the outer one which is coupled to the store, and then another one which just receives props from the outer one?
@АлМ-ы8ъ
@АлМ-ы8ъ 4 жыл бұрын
Why we must use 'get' insted simple function?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey! I'm not sure why MobX prefers that for computed properties, but this is what `get` is: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
@gikizayKG
@gikizayKG 4 жыл бұрын
How can i create multiple useLocalStore? pls help
@leighhalliday
@leighhalliday 4 жыл бұрын
Ask and you shall receive: mobx-react.js.org/recipes-context#multiple-global-stores
@finzaikofin
@finzaikofin 5 жыл бұрын
Thanks bro, waiting for next lesson I saw udemy.com currently migrate from old angularjs to react+mobx
@leighhalliday
@leighhalliday 5 жыл бұрын
Thanks Finz! I'm working on more ideas :)
@Norfeldt
@Norfeldt 5 жыл бұрын
As always interesting content and great teaching. Thank you very much. It would be interesting if you did a second video with the exact same bug app but using useReducer (instead of MobX) and did a quick comparison between the two.
@leighhalliday
@leighhalliday 5 жыл бұрын
Hey Norfeldt! Check out this video I published on the LogRocket channel kzbin.info/www/bejne/m3O8e2qFaZ1lesU
@backendfyi
@backendfyi 5 жыл бұрын
Thank you so much for this tutorial
@leighhalliday
@leighhalliday 5 жыл бұрын
Thanks for watching, Felix! Glad you enjoyed it :)
@backendfyi
@backendfyi 5 жыл бұрын
Leigh Halliday you’re welcome 😉
@MrAshwinpatel308
@MrAshwinpatel308 4 жыл бұрын
It was really nice video with perfect and required info. Could u pls make any video for next level in which u can include architecture with service call?
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks Ashwin! I'm waiting for MobX 6 and then I'll dive in a little more. For external "state" (meaning interaction with services, apis, etc...), I honestly think I'd prefer to use Apollo if it were GraphQL, or something like useSWR or react-query for REST APIs.
@les2997
@les2997 5 жыл бұрын
If I have multiple MobX stores, is it better to put them all in a single provider or should there be multiple providers each providing a single MobX store?
@leighhalliday
@leighhalliday 5 жыл бұрын
Hey Les! I personally don't know, but their documentation has a section covering this I believe: mobx-react.js.org/recipes-context#multiple-global-stores
@radovansurlak7445
@radovansurlak7445 3 жыл бұрын
Thanks Leigh :)
@leighhalliday
@leighhalliday 3 жыл бұрын
You're very welcome! I am planning on doing a new 2021 version shortly!
@giuliotiseo2693
@giuliotiseo2693 5 жыл бұрын
Finally a good explanation of MobX + React. Thank you! I would ask you just a thing: what is the best approach for a larger store? I have a huge form and I think that manage all the data will be painfull. Is there any good pattern for more complex solution?
@leighhalliday
@leighhalliday 5 жыл бұрын
Thanks, Giulio! Hmmm... if it were a single form, to be honest I don't think I'd even use MobX... I'd probably just stick with local state, or use something like Formik which sort of manages the form values for you. If you did want to do it in MobX, I wouldn't shy away from a large store unless you are storing completely unrelated data. For multiple stores, check out this section here in their docs on how to potentially tackle it: mobx-react.js.org/recipes-context#multiple-global-stores
@giuliotiseo2693
@giuliotiseo2693 5 жыл бұрын
@@leighhalliday Right, thank you for the good tips :D
@marcelorecio3208
@marcelorecio3208 4 жыл бұрын
what about persisting a store using this MobX approach?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Marcelo! I think the best way would be if you can "observe" changes to your store, and sync those to local storage (I assume this is what you mean)... but I couldn't see an easy way to do this with hooks. There must be a way, I just wasn't able to find one. Let me know if you figure it out!
@wedding_photography
@wedding_photography 4 жыл бұрын
From that example it's not clear at all how StoreContext is passed to the child components, if they aren't in the same .js file. Do you have to drill it all the way down?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey olegkikin! The file that contains `StoreContext` must export it, and then you can import the `StoreContext` into any component you want to use it in. Then you use `const store = React.useContext(StoreContext)` to actually access the store within your React component. Sorry, I put it all in a single file to make it easier to show in one place, but I see how that would make things more confusing.
@wedding_photography
@wedding_photography 4 жыл бұрын
@@leighhalliday I'm pretty sure that only works for functional components, not class components.
@leighhalliday
@leighhalliday 4 жыл бұрын
Yessir. Sorry that's all I've been building ever since hooks came out. Truth is this video won't help you at all for class components, you might want to check out my older mobx video from a couple years ago, it should help!
@stanna23
@stanna23 4 жыл бұрын
In this example, why wouldn’t I just use context? I can omit using the observer by just wrapping it up in a context consumer. This way I’d have no external dependencies that I have to worry about and all my implementation is from react.
@leighhalliday
@leighhalliday 4 жыл бұрын
You can just go with useContext, useState, useReducer, useEffect, etc... MobX or Redux aren't necessary. Use whatever you enjoy the most :) React is a lot better these days at sharing global state than when MobX and Redux first became popular. Either way, I'd start with local state and only bubble it up higher in the component tree when necessary.
@stanna23
@stanna23 4 жыл бұрын
@@leighhalliday thank you for the reply and clearing it up!
@nipunravisara389
@nipunravisara389 5 жыл бұрын
Good explanation, Thanks
@leighhalliday
@leighhalliday 5 жыл бұрын
Thank you Nipun :)
@preyashhojiwala6626
@preyashhojiwala6626 5 жыл бұрын
Which is the best state management library? React.Context, unstated, mobx, redux, redux thunk, apollo link state or something else
@leighhalliday
@leighhalliday 5 жыл бұрын
Hey Preyash! They are all good, choose the one you like the most! Check out mobx state tree as well, it's pretty cool.
@preyashhojiwala6626
@preyashhojiwala6626 5 жыл бұрын
@@leighhalliday Currently using mobx but I ain't getting the full vibe so just today started with unstated, I think it's cool.
@vasileturus
@vasileturus 5 жыл бұрын
Very cool, thanks!
@leighhalliday
@leighhalliday 5 жыл бұрын
Glad you enjoyed it d d!
@ionutcirja7121
@ionutcirja7121 4 жыл бұрын
Can't really see any advantage in mutating state... Another thing I really would hate in a big app (where not everything will not be in one file) is to remember the names of all the methods from the store in order to update the date. But I suppose nothing can be perfect, right?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Ionut! Thanks for watching. I *think* it's possible to have multiple mobx stores if one gets too big. But I also think you'd run into the problem with any state management library in a very large application... how to know what all the redux actions that you can dispatch are?
@ionutcirja7121
@ionutcirja7121 4 жыл бұрын
@@leighhalliday You are right Leigh. Forgot to say thanks for the video. I think I will give a try to mobx in my next project... which starts right now :)
@nocoolming
@nocoolming 4 жыл бұрын
Can you teach us about mobx react navigation integration?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey! Hmmm.... I've never done that before... if I come across it in a project, I'll definitely tackle it in a video.
@nocoolming
@nocoolming 4 жыл бұрын
Can you open source a mobx react native example project like pet store? In this way, we can see how mobx implements business in real project scenarios, thank you
@ilyasoloveychik4504
@ilyasoloveychik4504 4 жыл бұрын
thanks a lot! I hope it will help me deal with these React States better ;)
@leighhalliday
@leighhalliday 4 жыл бұрын
Excellent! That's my goal, to help people get to the next level or get past a problem they're facing!
@mrginn
@mrginn 3 жыл бұрын
Thank you!
@SEOTADEO
@SEOTADEO 4 жыл бұрын
thanks for this video. Was fiddeling around with xstate before but it was too intimidating.
@leighhalliday
@leighhalliday 4 жыл бұрын
You're welcome! Glad you enjoyed it :)
@amidaobscura
@amidaobscura 4 жыл бұрын
Why use context with Mobx? You need a lot of boilerplate to setup the context and in the end you have to import the provider like a global variable.
@leighhalliday
@leighhalliday 4 жыл бұрын
I used it so that I can provide my mobx state globally to the rest of the application.
@amidaobscura
@amidaobscura 4 жыл бұрын
@@leighhalliday But context is not needed for that. You can import the global store directly.
@gerda-morozova
@gerda-morozova 4 жыл бұрын
Hi, I have one question. Am I right what in MobX use React.Context for providing global data, like Provider in react-redux? Or it one of example how we can manage data with MobX? P.S. sorry for bad english anyway
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey! You're correct, React.Context is exactly for the purpose of sharing global data... it will give you a Provider which is the same idea that you see in Redux.
@kylemcshea9433
@kylemcshea9433 4 жыл бұрын
Not sure the root of this error: Line 23:17: React Hook "React.useContext" is called in function "colorHeader" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks Line 24:10: React Hook "useObserver" is called in function "colorHeader" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks EDIT: I am dumb I pulled the rookie mistake of forgetting to Capitalize Component names, Keeping this comment up incase any other newbies have this issue
@leighhalliday
@leighhalliday 4 жыл бұрын
Hehe, glad you figured it out cause I was definitely stumped! Thanks for sharing the solution!
@markodivji
@markodivji 4 жыл бұрын
Which there are you using in VSCode?
@leighhalliday
@leighhalliday 4 жыл бұрын
One Monokai
@markodivji
@markodivji 4 жыл бұрын
@@leighhalliday Ty mate :)
@BearkFearGamer
@BearkFearGamer 5 жыл бұрын
Awesome, maybe you can make a video about mobx-persist or something like that
@leighhalliday
@leighhalliday 5 жыл бұрын
Thanks Beark! I'll see what I can do. I haven't used mobx-persist before.
@trta90_42
@trta90_42 5 жыл бұрын
Tnx alot man, realy good stuff
@leighhalliday
@leighhalliday 5 жыл бұрын
Thanks trta90!
@tiagoagm
@tiagoagm 4 жыл бұрын
Thanks for the tutorial. It seems I will be using MobX instead of redux. 🙂
@leighhalliday
@leighhalliday 4 жыл бұрын
Cheers Tiago! Let me know what you think when you give it a try (hit me up on Twitter because it's hard to see comment replies on KZbin)
@tiagoagm
@tiagoagm 4 жыл бұрын
Maybe, you could build a more complex project using MobX in your next video.
@tiagoagm
@tiagoagm 4 жыл бұрын
@@leighhalliday I have one question, instead of the action in useLocalStore you could just simply do "store.bugs.push(bug)" ?
@patrickren7395
@patrickren7395 4 жыл бұрын
I'm kinda confused, why use context when I can just import store in children components?
@leighhalliday
@leighhalliday 4 жыл бұрын
You could probably do that, Patrick... up to you! Just make sure to wrap `useObserver` or it probably won't detect changes and re-render.
@andrewpavlov9128
@andrewpavlov9128 4 жыл бұрын
This could be useful in unit testing to provide fake store implementation
@michaelblum4557
@michaelblum4557 4 жыл бұрын
Thanks so much for the video! Immensely helpful as always. I was wondering: are there any performance downsides to using Context in this, uh, context? As in, using it with MobX (which I take it is one of the more/most performant state management libraries). I've seen some poor performance when using Context in the past, and this seems to be the experience of others as well (see leewarrick.com/blog/the-problem-with-context/ and blog.theodo.com/2019/07/how-i-ruined-my-application-performances-by-using-react-context-instead-of-redux/, for example). Is this implementation exempt from some of those performance penalties because it's only using Context as a container / provider?
@leighhalliday
@leighhalliday 4 жыл бұрын
Hey Michael! There might be, but to be honest I don't really worry about performance until I notice an issue, and I haven't noticed any issues so far. I guess the things I do aren't so intensive that it matters. Let me know what you find!
@AbhishekNigam
@AbhishekNigam 4 жыл бұрын
Nice tutorial!
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks Abhishek! I appreciate it :)
@嘉石
@嘉石 3 жыл бұрын
Thank you
@leighhalliday
@leighhalliday 3 жыл бұрын
The pleasure was all mine!
@SHELLAC85
@SHELLAC85 4 жыл бұрын
Thanks for this :)
@leighhalliday
@leighhalliday 4 жыл бұрын
Thanks for watching and saying hi, Shellac85!
@ZiedHF
@ZiedHF 4 жыл бұрын
Thanks sir !
@leighhalliday
@leighhalliday 4 жыл бұрын
You're welcome Zied! Glad you enjoyed it!
@dennisgonzales9521
@dennisgonzales9521 4 жыл бұрын
Thankyou!
@leighhalliday
@leighhalliday 4 жыл бұрын
You're very welcome Dennis!
@Mannoeu
@Mannoeu 4 жыл бұрын
awesome!!!
@leighhalliday
@leighhalliday 4 жыл бұрын
Thank you very much Emmanuel!
@patcoston
@patcoston 3 жыл бұрын
I'm watching this in 2021.
@leighhalliday
@leighhalliday 3 жыл бұрын
Sweet! I actually did a new one for 2021 that I really like... make sure to check it out! kzbin.info/www/bejne/jYK0omSHl76fd9k
@les2997
@les2997 5 жыл бұрын
Hmm... this MobX documentation statement bothers me: "Note that using a local store might conflict with future React features like concurrent rendering." mobx-react.js.org/state-local
@leighhalliday
@leighhalliday 5 жыл бұрын
Guess we'll find out in the future 😜
How I Manage State in React
17:09
Leigh Halliday
Рет қаралды 33 М.
Async in MobX
17:56
Leigh Halliday
Рет қаралды 19 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
MobX Tutorial with React and Typescript
35:53
CodeDunks
Рет қаралды 19 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 876 М.
Understanding MobX vs Redux
4:12
Aria Fallah
Рет қаралды 44 М.
Typescript for React and MobX From Beginners to Masters
13:03
Jack Herrington
Рет қаралды 43 М.
XState - An introduction - Finite State Machines in React
8:06
Leigh Halliday
Рет қаралды 14 М.
Fetch Data With Mobx   Note Taking App Using React Mobx and Typescript
12:12
You don’t know MobX State Tree | Max Gallo | iJS London 2018
43:12
International JavaScript Conference
Рет қаралды 11 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН