rescript-react icon indicating copy to clipboard operation
rescript-react copied to clipboard

feat: strict types for form events

Open ivan-demchenko opened this issue 2 years ago • 1 comments

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);
    }
  }
/>

ivan-demchenko avatar Dec 01 '23 14:12 ivan-demchenko

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?

mununki avatar Jan 08 '24 16:01 mununki