rescript-react
rescript-react copied to clipboard
feat: strict types for form events
This PR makes use of Js.Json.t instead of object type for form events. It addresses this issue:
https://github.com/rescript-lang/rescript-react/issues/105
Context:
let targetValueToInt = (target: Js.Json.t): int => {
// Js.Json.decodeObject(target))
// and so on
}
// ...
<input
onChange={
evt => {
setIntValue(_prev => evt->ReactEvent.Form.target->targetValueToInt);
}
}
/>
Thank you for PR! The big difference between object and JSON is that undefined doesn't exist in JSON's specification. I'm not sure why we need to type-define form event as JSON format instead of object, can you explain further?