Closed dai-shi closed 5 years ago
Option 1: we rotate the index. % 31
Option 2: we use multiple contexts for each 31 items.
Option 3: multiple contexts for each items. Do not rely on observedBits
Assuming you abstract the implementation away from the user, I guess the decision criteria are (?)
I don’t know enough about the implementation of Context in the react codebase to know if #1 is a concern.
It’s still not clear to me how we may subscribe to deep state or if that is even desirable considering we can receive a state change for the high level state but avoid re renders using things like memo() for functional components and useMemo for computed values.
Thanks. I'm not sure either how much overhead creating hundreds of contexts leads.
Another concern is whether observedBits
will ever be official...
BTW, https://github.com/dai-shi/react-context-global-state is already taking the Option 3 approach.
but avoid re renders using things like memo()
something like this?
11_deep / Person.tsx
const PersonFirstName = () => {
const [value] = useGlobalState('person');
const { firstName } = value;
return useMemo(
() => (
<div>
First Name:
<TextBox text={firstName} />
<input
value={firstName}
onChange={setFirstName}
/>
</div>
),
[firstName]);
};
Yeah, that's exactly what I had in mind for useMemo.
Option 4: we pass non-updating "store" in the context, and let hooks subscribe for key-based changes. This is mostly like the previous implementation which requires useState
.
Turns out that the current implementation already takes the option 1 approach. I keep it as is, otherwise the library implementation gets much bigger. This limitation should be clearly noted in README.md.
Discussion from https://link.medium.com/gXvqudhDNR