Heim >Web-Frontend >js-Tutorial >Ereignisbehandlung in 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!
Das obige ist der detaillierte Inhalt vonEreignisbehandlung in React. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!