The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Key Topics Covered:
1) Adding Event Listeners to Components.
2) Common Event Handlers (onClick, onChange, etc.).
3) Updating State Based on User Input.
Updated App.js File:
App.js
import React from 'react';
class Comp1 extends React.Component {
state = { inputValue: null };
handleClick = () => { alert("Button Clicked."); };
handleChange = (event) => { this.setState({ inputValue: event.target.value }); };
render() {
return (<div>
<input type='text' onChange={this.handleChange} value={this.state.inputValue} />
<button onClick={this.handleClick}>Button to click</button>
<p>User Input: {this.state.inputValue}</p>
</div>);
}
}
function App() {
return (<div>
<Comp1 />
</div>);
}
export default App;