3 ms·
With passing values between hooks do you mean "Make one hook depend on the value of another hook?". Because that seems like the functor 'map', or applicative 'a
by sfvisser 8y ago
With passing values between hooks do you mean "Make one hook depend on the value of another hook?". Because that seems like the functor 'map', or applicative 'apply'.
Note, I don't really know what these springs are, but derived hooks could work like this:
class MyComp extends ReactishComponent {
fast = this.use(new Spring({ pos: [0, 0], config: "fast" })) // prim hook
slow = this.use(this.fast.map(spring => ({ pos: spring.pos, config: "slow" }))) // functor map
mid = this.use(combineTwoHooks((fast, slow) => computeMiddle(fast, slow), this.fast, this.slow)) // applicative
render() {
return (
<>
<Point pos={this.fast.get().pos} />
<Point pos={this.slow.get().pos} />
<Point pos={this.mid.get().pos} />
</>
)
}
}
The trick is functions that convert hooks into new hooks.