Question - How do you create an event in React?
Answer -
We can create an event as follows.
class Display extends React.Component({
show(msgEvent) {
// code
},
render() {
// Here, we render the div with an onClick prop
return (
);
}
});
Example
import React, { Component } from 'react';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
companyName: ''
};
}
changeText(event) {
this.setState({
companyName: event.target.value
});
}
render() {
return (
Simple Event Example
You entered: { this.state.companyName }
);
}
}