In the ReasonReact docs, under Callback Handlers, it says this:
To access
state
,send
and the other items inself
from a callback, you need to wrap the callback in an extra layer calledself.handle
But then, under State, Actions & Reducer:
In
render
, instead ofself.handle
(which doesn’t allow state updates), you’d useself.send
.send
takes an action.
In my code, I often forget about self.handle
, and just pass a callback to a child component like this:
onLayout={event => self.send(
UpdateHeight(event->BsReactNative.RNEvent.NativeLayoutEvent.layout.height)
)}
or like this:
onSubmit={() => submit(self.state)}
It works fine, at least as far as I can tell. Am I storing up problems for future Ben? Should I be using self.handle
? And if so, exactly when should I be using it?
Thanks for any insight you can give!