Event handling in React allows you to respond to user interactions like clicks, form submissions, and other events. Here’s a basic overview and example:
Here's a simple example of handling a button click and an input change:
import React, { useState } from 'react'; const EventHandlingExample = () => { const [inputValue, setInputValue] = useState(''); const handleClick = () => { alert(`Button clicked! Input value: ${inputValue}`); }; const handleChange = (event) => { setInputValue(event.target.value); }; return ( <div> <input type="text" value={inputValue} onChange={handleChange} placeholder="Type something..." /> <button onClick={handleClick}>Click Me</button> </div> ); }; export default EventHandlingExample;
Feel free to ask if you need specific examples or further explanations!
以上がReact でのイベント処理の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。