import { useRef } from "react";
const sendInput = (inputValue: string | undefined) => {
console.log(inputValue)
}
function App() {
const inputRef = useRef<HTMLInputElement>(null);
return (
<div className="App">
<input ref={inputRef} type="text" />
<button onClick={()=>sendInput(inputRef.current?.value)}>送信</button>
</div>
);
}
export default App;
More than 3 years have passed since last update.
【TypeScript】useRefを使ってテキストフィールド実装
Last updated at Posted at 2021-10-16
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme