ReactJS - Events

 Just like HTML, React can perform actions predicated on utilizer events. React has the same events as HTML: click, change, mouseover, etc.


React events are written in camelCase syntax:

onClick instead of onclick.

React event handlers are written inside curly braces:

onClick={trigger}  instead of onClick="trigger()".

Example

import React, { Component } from 'react';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
message: ''
};
}
changeText(event) {
this.setState({
message: event.target.value
});
}
render() {
return (
<div class="container">
<h2>Simple Event Example</h2>

<div className="form-group">
<label htmlFor="usr">Enter your message: </label>
<input type="text" id="message" onChange=
                          {this.changeText.bind(this)} />
</div>

<h4>You entered: {this.state.message}</h4>
</div>
);
}
}
export default App;
  

Output:

When you execute the above code, you will get the following output.

After entering the denomination in the textbox, you will get the output as like below screen.

CRUD

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete