3 ms·
Following React conventions is certainly an option and is supported by SimpleR State's unopinionated and flexible syntax. 1. It was inadvertently removed from
by aenero 6y ago
Following React conventions is certainly an option and is supported by SimpleR State's unopinionated and flexible syntax.
1. It was inadvertently removed from the documentation, but these are equivalent:
const count = counter.use()
const count = useEntity(counter)
but the `counter.use()` was chosen in the documentation due to more feedback that requested this "simpler" format (i.e. no need to import `useEntity()`. But again, to your point I will restore the mention of `useEntity` in the documentation.
2. As for the [state, setState] convention, think of useEntity more like useContext than useState. Then it gets simpler.
3. I would also argue that since this is "shared" state, the developer might (again, the library is not opinionated on this) choose to separate the logic of updating shared state. For this reason, I didn't see any reason to provide a setter through the hook, when you can access the setter from anywhere via something like counter.set(). Conforming to useState convention was not justified in this case, especially since useContext convention equally makes sense for shared state.
4. To suit whatever convention, you can always do something like this alongside the definition of the entity:
export const useCounter = counter.use
I want to point out that SimpleR State provides the flexible constructs to allow the developer to tailor it to their preferred convention.
Thanks for your feedback.