• +91 9723535972
  • info@interviewmaterial.com

ReactJS Interview Questions and Answers

Related Subjects

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 (              
         
Click Me
   
        );      
    }  
});  
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 }

  
           
  
        );  
    }  
}  

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners