What is a Component in ReactJS?

 Posted by Rajnilari2015 on 12/7/2015 | Category: JavaScript Interview questions | Views: 2316 | Points: 40
Answer:

A component is that feature of React which comprises of an html along with it's associated JS satisfying the SRP principle.React components implement a render() method that takes input data as Component and returns the string after rendering as what to display. e.g.

<div id="mountNode"></div>

var CustomMessage = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});

ReactDOM.render(<CustomMessage name="DNF" />, mountNode);


Output
----------

Hello DNF


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response