DocsAPISyntaxReactPlaygroundBlogCommunity
  • Playground
  • Blog
  • Community
  • X
  • Bluesky
  • GitHub
  • Forum
rescript-react
Overview
  • Introduction
  • Installation
  • Migrate from JSX v3
Main Concepts
  • Elements & JSX
  • Rendering Elements
  • Components and Props
  • Arrays and Keys
  • Events
    • Capture the input value onChange
  • Refs and the DOM
  • Context
  • memo
  • Styling
  • Router
  • Lazy Components
  • Import / Export ReactJS
Hooks & State Management
  • Hooks & State Management Overview
  • useEffect Hook
  • useState Hook
  • useReducer Hook
  • useContext Hook
  • useRef Hook
  • Build A Custom Hook
Guides
  • Beyond JSX
  • Forwarding Refs
  • Extensions of props
Extra
  • LLMs
Docs / rescript-react / Events
Edit

Events

React lets you add event handlers to your JSX. Event handlers are your own functions that will be triggered in response to interactions like clicking, hovering, focusing form inputs, and so on.

Capture the input value onChange

Depending on the event handler, the callback function will have a different type. Due to the dynamic nature of JavaScript, we cannot anticipate the target type on the event. So, we need a leap of faith to grab the input value as string.

RES
module App = { @react.component let make = () => { let (value, setValue) = React.useState(_ => "") <form> <input type_="text" defaultValue={value} onChange={(ev: JsxEvent.Form.t) => { let target = JsxEvent.Form.target(ev) let value: string = target["value"] setValue(_prevValue => value) }} /> <p style={{color:"red"}}>{React.string(value)}</p> </form> } }
Arrays and KeysRefs and the DOM

© 2025 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on