-
컴포넌트 간 state 주고받기Study/React 2020. 6. 1. 19:53
import와 export를 통해,
컴포넌트 간의 state 정보를 주고 받을 수 있다.
//Parent.js import React from 'react'; import ReactDOM from 'react-dom'; import { Child } from './Child'; class Parent extends React.Component { constructor(props) { super(props); this.state = { name: 'Frarthur' }; } render() { return <Child name={this.state.name} />; } } ReactDOM.render(<Parent />, document.getElementById('app'));
//Child.js import React from 'react'; export class Child extends React.Component { render() { return <h1>Hey, my name is {this.props.name}!</h1>; } }
'Study > React' 카테고리의 다른 글
Don't Update props (0) 2020.06.01 component State (부제. state와 props의 차이점) (0) 2020.06.01 Update state with this.setState (2) 2020.05.27 Access a Component's state (0) 2020.05.27 state (0) 2020.05.27