My Authors
Read all threads
#MobX or @recoiljs? Saw a lot of questions on whether they're the same, so a quick thread. First of all, Recoil & MobX solve the same problem: efficient render widely shared state. This is a problem React (Context), Redux and most state management libs don't solve.
In that regard they are very similar. Hence terminology aligns: atoms, dep trees, derived data .Roughly speaking Recoil offers observable.box + computed + useObserver from MobX. A difference is that Recoil builds on React primitives, the benefits are clear:
Leaner, more easily compatible with concurrent mode, piggy back on React's batching. MobX in contrast is more general purpose and can be used in non-React projects and is even ported to different languages (eg Flutter) & doesn't need a React context to work or organize effects
MobX, like Recoil is build around atoms. But in MobX they are abstracted away in objects, maps, arrays, etc. More magic, but makes atoms easier composable / nestable. Concretely: no need to organize a separate atom for the collection (ids) & atoms for the individual objects
In MobX that is done under the hood for you by e.g. observable.array
More importantly, in MobX you always get an atom for each prop. That means that a component rendering one field, won't respond to updates in other fields in the same object. The same can be achieved in recoil,
but you have to organize it yourself (either write a selector, or organize the state in smaller atoms). That brings us to the last important difference: In recoiljs you explicity specify what you consume. That is clearer, but also less optimal. Beyond being more course,
due to the nature of react hooks, it has to be unconditional (or requires additional selectors). "<div>{user.loggedIn ? user.name : ""}</div>" will only subscribe to user.name as long as user.loggedIn is true in MobX. That is hard to achieve manually
To summarize: Recoil & MobX are similar: many, individual subscribable atoms (Redux has always one), enabling sideways comp updates + model that favors deriving & memoizing data. MobX offers higher level abstractions like maps and arrays based on atoms + transparent tracking
Recoil integrates much more closely with React and is purer.
Disclaimer: above is based on just watching the talk, I haven't further used the project. Just want to elaborate on what looks similarly, and what differently to me. Definitely check it out!
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Michel Weststrate

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!