saasquatch / bunshi

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

When molecule returns a function, useMolecule should also return the same function #46

Closed 3846masa closed 7 months ago

3846masa commented 7 months ago

Description of the change

When the return value of molecule is a function, for example, atomFamily, the return value of useMolecule is the result of the execution of that function.

This is because useState executes a function when it receives a function as an argument.

In this PR, make the argument given to useState a function whose value is wrapped as a setter. This prevents unexpected function execution and returns the value from useMolecule as expected.

(translated by DeepL)

Type of change

Links

Checklists

Development

Paperwork

Code review