props are usually defined in parent components. 

class App extends React.Component {
	render() {
		return (
			<div>
				<Hello to="Ringo" from="Paul" />
				<Hello to="Cher" from="Sonny" />
			</div>
		);
	}
}


ReactDOM.render(<App />, document.getElementById('root'));
class Hello extends React.Component {
    render() {
        //console.log(this.props.to);// properties that passed

        // don't change the prop here.
        // ex) this.props.to = "Blue"; -> this will give you red lines, lots of err!!!

        const props = this.props;
        return <h1>Hello {props.to} from {props.from}!</h1>;
    }
}

 

'react' 카테고리의 다른 글

Props : slot machine exercise  (0) 2020.06.13
Props : types of props  (0) 2020.06.13
Introducing JSX : basic concept of React layout  (0) 2020.06.13
Introducing JSX : conditionals  (0) 2020.06.13
Introducing JSX : basic  (0) 2020.06.13