Note: This is only a proof of concept, not for production use yet.
let ContentView = { RendererView { hooks in
let (counter, setCounter) = hooks.useState(initial: 0)
hooks.useEffect {
if counter == 5 {
alert("High five!")
}
}
hooks.useEffect({
alert("Hi there!")
}, dep: RendererView.triggerOnce)
return VStack {
Text("Current value: \(counter)")
HStack {
Button(action: { setCounter(counter + 1) }) { Text("+") }
Button(action: { setCounter(counter - 1) }) { Text("-") }
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)>*
} }
This is fully inspired by React Hooks. To learn more about what hooks are doing, please first check out the React documentation. And the API design in this PoC also follows the React spec, you can literally map what you learned to this.
TBD.
See RendererView.swift.
-
useEffect
with cleanup. - Detection of inconsistent hook calls.
- ...
This repository won't accept PRs about detail design. If you are interested in making it a library, feel free to leave an issue and let me know.