This is a walkthrough on how to get a full setup with mobx-state-tree and react in a CRA app with typescript. This guide doesn't focus too much on ...
For further actions, you may consider blocking this person and/or reporting abuse
Hey Margarita, thanks for your post. Learned a lot.
Btw, I still don't understand what you said,
useInject
is better thanuseStore
when using complicated store. UseuseStore
we still can get what we want.Hey!
Great to hear it was helpful :)
When I implemented the
useInject
hook, I was thinking about having something similar to customizing inject with a mapper function, but with hooks. So if you have a more complicated app with lots of things in your store, or if you need to combine data from several stores, you might want to just extract all the data your component needs in a mapper function and then not care about how you get that data from the stores in your component.For example,
Then you abstract away some details of your store implementation from your component's code. But I agree that it doesn't seem like a big problem to just use
useStore
, and since I am really used toredux
and itsmapStateToProps
, I was trying to make it more comfortable for myself to develop withmst
by using familiar concepts.There is even a discussion about creating a similar
useInject
hook in this github issue.However, when I tried the example above, I noticed an error in my implementation of
useInject
, which makes it confuse the return type from the mapper function because of this:(mapStore || defaultMapStore)(store)
, which is supposed to allow omittingmapStore
parameter in the hook. On my way to fixing this, thanks a lot for making me notice the error! :)Thanks for your detailed explanation!
useInject
is a bit complicate to me, so I'm sticking to useuseStore
:-)And another thing I found when I try your great example is enhanced the
useStore
with types:to
Then it will be more convenience to use
useStore
with ts autocomplete feature!Hey Margarita, thanks so much for this amazing article, I'm seeing that my knowledge on mst is a little rusty and this lecture helps me to be updated on it
Looking forward for more publications like this, for example, how do you organize remote side effects?
Hey! Thank you for your feedback, glad that the article helped you :)
I haven't had time to look into side effects with
mst
yet, but it is definitely on my todo list ;)thank you for this great article.
The same approach can be used for react native as well?
Thanks for the feedback!
I am not sure about
react-native
to be honest, haven't worked with it, but I think it should be the same, since it is tillreact
:)It is actually the same :)
Hi Margarita! Thanks for the post. Super helpful. Question .. how would you go about mocking the provider for tests and Storybook integration?