-
Notifications
You must be signed in to change notification settings - Fork 39
Closed
Description
Similar to React Hooks. RFC discussion.
The differences being
- The use of a single setter/getter stream instead of a tuple. So
value = use(value)instead of[value, setValue] = use(value). This allows us to use live values to avoid the age old problem of stale data. That isvalue()would always return the current value. - The unification of hooks and effects into a single
useAPI. i.euse(value)anduse(value, callback)instead ofuseStateanduseEffect. - Support for unmount animations as can be archived with
componentWillUnmount. Without which hooks wouldn't have full feature parity with lifecycle methods. - ...and passing
[dependencies], props, state, contextto the effect callback to effectively avoid being tied to closures.
An example of the aforementioned might look like the following:
import {h, use, render} from 'dyo'
function Counter (props, {refs, value = use(0)}, context) {
try {
return h('div', {ref: refs},
h('button', {onClick: e => value(value + 1)}, '+'),
h('button', {onClick: e => value(value - 1)}, '-'),
h('h1', {}, value)
)
} finally {
useAnimation(value)
}
}
function useAnimation (value) {
return use([value], ([value], props, {refs}, context) => {
return () => {
return refs.current.animate([], {}).finished
}
})
}Point 3 arises the question of how do we handle the case when multiple effects try to register unmount animations: Do we 1. Register all the animations? or 2. Register the last animation?
Metadata
Metadata
Assignees
Labels
No labels