[discussion] ReSub Hook API
See original GitHub issueI was wondering whether there are any plans to officialy support React Hooks. I only found a discussion regarding lifecycle changes (#78) but could not find a mention of the now introduced Hooks.
It is definitely possible to use them, I have made an example repository as a proof of concept here: https://github.com/Hizoul/ReSubHooksTest
Ideally I imagine the API to work the same as _buildState so like this:
const state = useResub(() => {
value: FormStore.getValue("My key")
})
(Where FormStore is an autosubscribe score that has an @key decorator on its first argument) Unfortunately due to my lack of understanding of decorators and how automatic subscriptions work I was only able to come up with a solution that requires the key to be specified explicitly.
const state = useResub(FormStore, "My key", {name: "getValue", arguments: ["My key"]})
The hook implementation with annotations for parts that need to be improved can be found here: https://github.com/Hizoul/ReSubHooksTest/blob/master/src/resubHook.js
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Thank you for the clarification! In the unlikely event of me figuring out an implementation that supports the automatic subscriptions I will let you know. I wouldn’t dare opening a pull request for the ugly Proof-of-Concept API portrayed in the second code block.
I ended up adding a hook-like API to use for now. We may also someday add a full useResub() state-builder, if there’s demand for it.