crimx / observable-hooks

⚛️☯️💪 React hooks for RxJS Observables. Concurrent mode safe.
https://observable-hooks.js.org
MIT License
1.03k stars 44 forks source link

Question - descendent re-rendering? #119

Closed dakom closed 1 year ago

dakom commented 1 year ago

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 1 year ago

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 1 year ago

Thanks, that's great!