FormidableLabs / freactal

Clean and robust state management for React and React-like libs.
MIT License
1.65k stars 46 forks source link

Shared(global) state for some use cases #45

Open pronevich opened 7 years ago

pronevich commented 7 years ago

As I understand, freactal provide only local state concept. Maybe it would be make sense to add possibility to share some state (example: between pages in next.js) without composition on app root for preventing reconciliation on whole components tree.

Here @divmain twits about it https://twitter.com/divmain/status/861077765830852608

divmain commented 7 years ago

This is a tricky thing, and I'm not sure of the best way to go about accomplishing what you're attempting here. I'm not super familiar with Next.js yet, either, so it may take a bit of research before I come to a satisfying answer. If any other folks have ideas, I'm open to hearing them!

stefanmaric commented 6 years ago

I'm going to reference some related discussions here:

https://github.com/mobxjs/mobx/issues/300 https://github.com/mobxjs/mobx/issues/605

divmain commented 6 years ago

@pronevich, I've been thinking about your question a bit more, and this stuck out to me:

reconciliation on whole components tree

Is this happening for you? Due to how state is injected into components, a piece of state that is 1) tracked at the top level and 2) changed, should not result in a full VDOM reconciliation. It will result in a state reconciliation, checking whether the change in state should result in any re-renders, but this should be much less expensive (and honestly, exactly what we want).

Am I understanding the issue correctly?

pronevich commented 6 years ago

Yes, exactly as you explain it

divmain commented 6 years ago

Would you be able to provide a reduced repro? I'm definitely interested in seeing areas where the state reconciliation results in an unnecessary VDOM reconciliation.