Rumah >hujung hadapan web >tutorial js >Pengendalian Acara dalam React
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!
Atas ialah kandungan terperinci Pengendalian Acara dalam React. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!