Props
Add Rating component in App.js
import React, { Component } from 'react';
import Rating from './Rating'; /* Look Here */
class App extends Component {
render() {
const isValid = true;
return (
<div className="App">
<Rating rating="1"/> /* Look Here */
</div>
);
}
}
export default App;
We can pass data into a component using this.props in Rating.js
import React, {Component} from 'react';
class Rating extends Component {
render() {
/* this.props.rating (from <Rating rating="1">) */
return (
<h1>
Rating: { this.props.rating } /* Look Here */
</h1>
);
}
}
export default Rating;
React DOM
We call render() in App.js with < Rating rating="1" />. React calls the Rating component with {rating: 1} as the props. Rating component returns a < h1>Rating: 1 element, and React DOM updates the real DOM. Props object may contain multiple and even complex objects as attribute(s).Questions and answers
You can pass data into a component using ...
- a) this.props
- b) this.state
Props object can contain multiple attributes
- a) true
- b) false
Can you modify props?
- a) Yes, props are read-only
- b) No