diegohaz/constate

is there a way for consumer to set inputs for rerendering?

alidcast opened this issue · 4 comments

in other words, for a consumer to select which inputs from state it'd like to trigger rendering for

React Context has an experimental feature called observedBits. You can pass a calculateObservedBits function in the second parameter of createContext and pass the relevant bits in the second parameter of useContext (or to the unstable_observedBits prop on Consumer).

didn't this lib handle this for the end user in a previous version of constate? I say that because im aware of observerBits but imo it'd be preferable to have this handled at the library level

Yep! The current API is the result of some experimenting with several others around React Hooks. You can find them all here: https://github.com/diegohaz/constate/blob/master/CHANGELOG.md

In a previous version, there was only one Context/Provider for the whole state, so it made sense to limit re-renders on consumers based on slices of that state (namely context keys).

I don't think it makes too much sense introducing this kind of complexity now that contexts are more granular. Even if it did, I can't think on a way to do that since the state shape is unknown at the time the context is created.

yea, performance optimizations for hooks/context are yet to be fully figured out, there's a great discussing in this issue (I'll link it here in case you haven't seen it) facebook/react#14110

going to go ahead and close this, thanks for answering