1function Parent() {
2 const [value, setValue] = React.useState("");
3
4 function handleChange(newValue) {
5 setValue(newValue);
6 }
7
8 // We pass a callback to Child
9 return <Child value={value} onChange={handleChange} />;
10}
1function Child(props) {
2 function handleChange(event) {
3 // Here, we invoke the callback with the new value
4 props.onChange(event.target.value);
5 }
6
7 return <input value={props.value} onChange={handleChange} />
8}