Inspired by useFormField, which is controller of some part of DOM, same time the component itself is controller too.
useComponent takes some element (at least), or some reference to component instance, returns state and actions.
let [state, actions] = useComponent(ref)
this logically binds current component function to any state updates of source component.
Therefore component should be able to export state and actions. React exports view, not state/actions.
With useState, useAction we export parts of the API, defined by some component.
With useComponent we can export state/actions together.
// create component exports
function Cart(){
useComponent('cart', [state, actions])
}
// use component from outside
function Comp() {
let [state, actions] = useComponent('cart')
}
1. That is very much similar to just useChannel(name, [state, actions]).
3. Hook name is just custom lens/controller/provider for a value.
It is value with additional logic.
At the core is value and its change. Reactions subscribe to various values in various places: dom elements, model, function, anything - simple subscriptions with fancy syntax. Instead of use we might as well use subscribe(channel, init?)
Inspired by useFormField, which is controller of some part of DOM, same time the component itself is controller too.
useComponent takes some element (at least), or some reference to component instance, returns state and actions.
this logically binds current component function to any state updates of source component. Therefore component should be able to export state and actions. React exports view, not state/actions.
With
useState
,useAction
we export parts of the API, defined by some component. WithuseComponent
we can export state/actions together.1. That is very much similar to just
useChannel(name, [state, actions])
.2.
useStore(key, fn)
===useAction
=== customizableuseChannel
.3. Hook name is just custom lens/controller/provider for a value.
It is value with additional logic.
At the core is value and its change. Reactions subscribe to various values in various places: dom elements, model, function, anything - simple subscriptions with fancy syntax. Instead of
use
we might as well usesubscribe(channel, init?)