crimx/observable-hooks

Question - descendent re-rendering?

dakom opened this issue · 2 comments

dakom commented

Wasn't sure the best place to ask this - but let's say I have observables A$ and B$ and this tree:

--Parent
----ChildA (reacts to A$)
----ChildB (reacts to B$)

Will ChildA re-render if B$ changes (or vice-versa?)

Basically I'm wondering if I have some global observables, do I still need a solution like Recoil to avoid needless re-renders on components that don't actually use those observables?

I'm also curious how exactly this works if there's no global store or tracking to optimize that :)

Thanks!

crimx commented

Will ChildA re-render if B$ changes (or vice-versa?)

No.

Basically I'm wondering if I have some global observables, do I still need a solution like Recoil to avoid needless re-renders on components that don't actually use those observables?

You don't need to.

I'm also curious how exactly this works if there's no global store or tracking to optimize that :)

Only Observable subscription triggers re-rendering. Passing the Observable will not trigger re-rendering if the Observable variable itself does not change. This is just how Observable works.

dakom commented

Thanks, that's great!