-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
App.jsx
import { useState, useRef, useEffect } from "react";
export default function App() {
const [value, setValue] = useState();
const ref = useRef(() => {
console.log("Submitted value:" + value);
});
useEffect(() => {
ref.current = () => {
console.log("Submitted value:" + value);
}
}, [value])
return (
<>
<input onChange={(e) => setValue(e.target.value)} />
<button onClick={() => ref.current()}>Submit</button>
</>
);
}