• +91 9723535972
  • info@interviewmaterial.com

ReactJS Interview Questions and Answers

Related Subjects

Question - How can you create a component in React?

Answer -

There are two possible ways to create a component in React:

Function Components: This is the simplest way to create a component in React. These are the pure JavaScript functions that accept props object as the first parameter and return React elements:

function Greeting({ message }) {  
  return

{`Hello, ${message}`}

  
}  
Class Components: The class components method facilitates you to use ES6 class to define a component. The above function component can be written as:

class Greeting extends React.Component {  
  render() {  
    return

{`Hello, ${this.props.message}`}

  
  }  
}  

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners