This closes #3 and some other issues discussed with @kenwheeler.
What this does:
Previously, state and effects were exposed to the user directly through the context. This was counter to recommendations from the React team, and I have slowly realized why :). That has been removed.
Instead, an injectState function is exposed to inject state and effects props into the wrapped component.
injectState-wrapped components subscribe to changes to the state container (and recursively, up the tree), which means that the entire tree will not re-render when the root state changes.
injectState is able to detect which state keys you use in its wrapped component, and will only re-render if those keys change in the state container.
You can override the above behavior by passing a second keys argument of shape ["key1", "key2"] to injectState. When specified, this disables the auto-detect feature and instead updates the wrapped component when the specified keys change.
The README has not seen changes yet - however, it'd be great to get feedback based on the changes to example/. If this is the way forward, there will be code comments and documentation updates before this is merged.
This closes #3 and some other issues discussed with @kenwheeler.
What this does:
state
andeffects
were exposed to the user directly through the context. This was counter to recommendations from the React team, and I have slowly realized why :). That has been removed.injectState
function is exposed to injectstate
andeffects
props into the wrapped component.injectState
-wrapped components subscribe to changes to the state container (and recursively, up the tree), which means that the entire tree will not re-render when the root state changes.injectState
is able to detect which state keys you use in its wrapped component, and will only re-render if those keys change in the state container.You can override the above behavior by passing a second
keys
argument of shape["key1", "key2"]
toinjectState
. When specified, this disables the auto-detect feature and instead updates the wrapped component when the specified keys change.The README has not seen changes yet - however, it'd be great to get feedback based on the changes to
example/
. If this is the way forward, there will be code comments and documentation updates before this is merged.@kenwheeler @aweary @ryan-roemer @baer @tptee @exogen @bmathews @chrisbolin