question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it different from MobX?

See original GitHub issue

I just found a comment by @FredyC in https://github.com/facebook/react/issues/15156#issuecomment-511097919.

@fuleinist Ultimately, it’s not that different from MobX, although a lot simplified for a specific use case. MobX already works like that (also using Proxies), the state is mutated and components who use specific bits of the state get re-rendered, nothing else.

I’m not very familiar with MobX, so please correct me if I’m wrong. As far as I understand, MobX uses Proxies to trap object mutations, not object property access in render function. I mean, what it’s providing is not an alternative to Redux/ReactHooks reducers. Theoretically, MobX is complementary to react-tracked. I’m not yet sure if/how it can be implemented, though. react-tracked doesn’t change the semantics of render function. It tracks the state usage and trigger re-renders. How to update state is not the focus of the library (at least at the moment).

I wrote an example to show the power of state usage tracking in the “Advanced Example” in https://blog.axlight.com/posts/effortless-render-optimization-with-state-usage-tracking-with-react-hooks/.


(edit) There was a misunderstanding of mine. useObserver tracks the state usage.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
mweststratecommented, Aug 5, 2019

Super cool project!

I’d have to tinker about this a bit more, but yes, I think this could potentially be useful for a completely alternative api to observer. The problem I was running into so from being able to say just useObserver(), is that we could already implement starting tracking for the current component, we just didn’t have a means to reliably end tracking for the current component. (Not fully sure that is unsolvable, but didn’t see a solution yet).

So this solution to create a proxy (if I understood it correctly from the source) per render, so that we every read an be traced back to the owning component solves that problem (granted, one has to has proxies).

On Mon, Aug 5, 2019 at 7:06 PM Daniel K. notifications@github.com wrote:

Uh…wow? 😃 You know, we were kinda fighting initially with this problem of needing observer around what’s being rendered to keep track of it. What’s the most surprising that it doesn’t actually re-render more than necessary. Just for a convenience a modified version which logs renderings.

https://codesandbox.io/s/peaceful-swartz-cn280

@mweststrate https://github.com/mweststrate Sorry, but I have to ping you in here, you have to see this 😃 ☝️

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dai-shi/react-tracked/issues/7?email_source=notifications&email_token=AAN4NBHF6BRNVGF7JG6NFMDQDBMYVA5CNFSM4IJLUHAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3SOL6Q#issuecomment-518317562, or mute the thread https://github.com/notifications/unsubscribe-auth/AAN4NBD6BWTYEOIQGDJZQQTQDBMYVANCNFSM4IJLUHAA .

1reaction
danielkczcommented, Aug 7, 2019

react-tracked is so tied to react local state and the state is updated immutably. So, I can’t simply use the bare Provider/useContext which would trigger all consumer components to re-render.

Makes sense. That’s what so great about MobX, because it has stores with stable reference, the Provider won’t even re-render in most cases. Only components accessing variables that have actually changed will render.

Recently, I wanted to use Formik V2, but there are so many issues related to immutability and that everything is recreated on each keystroke. I ended up writing my own form solution based on MobX and it’s awesome. It’s not for public consumption though (yet). I even wrote an article about it some time ago … https://levelup.gitconnected.com/formik-with-react-hooks-and-mobx-1493b5fd607e

That selector hook is definitely useful for immutable state, but in case of MobX not so much 😃

About your experiment, that’s something that I am afraid of too even for MobX, because useLocalStore might suffer there. The mobx-react-lite@next basically takes care of proper cleanup of reactions that were never committed, but it doesn’t solve a problem of local states.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux vs. MobX: Which performs better? - LogRocket Blog
Redux and MobX are two of the most popular external libraries that address state management in frontend applications.
Read more >
MobX vs Redux: A Comparison - Liquid Web
MobX is a battle-tested library that makes state management simple and scalable by transparently applying functional reactive programming (TFRP) ...
Read more >
Mobx vs Redux | Top 8 Useful Differences You Should Know
In Mobx, a lot of built-in abstraction is there, which leads to less code. In Redux, there is less abstraction and a need...
Read more >
Mobx vs Redux – Which Solution Is Better? | Codete Blog
Both Redux and MobX are used for monitoring state on the frontend, especially in JS apps. Both Redux and MobX are external libraries....
Read more >
Redux VS MobX | Comparison - Medium
Redux vs MobX similarities. When it comes to a comparison we always should talk about both similarities as well as differences.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found