saasquatch / bunshi

Molecule pattern for jotai, valtio, zustand, nanostores, xstate, react and vue
https://www.bunshi.org/
MIT License
230 stars 17 forks source link

Memoize scope provider context value #18

Closed jhoch-nmnl closed 1 year ago

jhoch-nmnl commented 1 year ago

Description of the change

I was testing whether jotai-molecules is a good fit for some of our state management needs, and ran into an issue during prototyping where a ScopeProvider would trigger downstream component renders more often than seemed necessary. I think I pinned down the problem, to an array instantiation that happens without memoization on every render of the ScopeProvider.

This change memoizes this array that is passed to the Context.Provider.

Note: I want to add a test or two to cover this but wanted to get feedback on whether this is a welcome change or not, first.

Type of change

Links

Checklists

Development

Paperwork

Code review

loganvolkers commented 1 year ago

@jhoch-nmnl the new version has a new format for doing context, so I think that this might no longer be the case.

If this seems like it's still a problem, can you please review and add a some test case? The testing was redone using vitest as part of V2

Finally, I'm very sorry that this has sat around so long without a comment or review. We'll try to do better going forward.