ReactJS - Create an Event-Aware Component

PHOTO EMBED

Wed Jun 05 2024 03:47:20 GMT+0000 (Coordinated Universal Time)

Saved by @varuspro9 #javascript

import React from 'react';

class MessageWithEvent extends React.Component {
   constructor(props) {
      super(props);

      this.logEventToConsole = this.logEventToConsole.bind();
   }
   logEventToConsole(e) {
      console.log(e.target.innerHTML);
   }
   render() {
      return (
         <div onClick={this.logEventToConsole}>
            <p>Hello {this.props.name}!</p>
         </div>
      );
   }
}
export default MessageWithEvent;
content_copyCOPY

https://www.tutorialspoint.com/reactjs/reactjs_create_event_aware_component.htm