console
class A extends React.Component{
constructor (props) {
super(props)
this.changeText = this.changeText.bind(this)
}
changeText (e) {
this.props.onTextChange(e.target.value)
}
render () {
let text = this.props.text
return (
<div>
<input value={text} onChange={this.changeText} />
</div>
)
}
}
class B extends React.Component{
constructor (props) {
super(props)
this.state = {
text: 'A的初始内容'
}
this.handleTextChange = this.handleTextChange.bind(this)
}
handleTextChange (value) {
this.setState({
text: value
})
}
render () {
let text = this.props.text
return (
<div>
<A text={this.state.text} onTextChange={this.handleTextChange} />
{this.state.text}
</div>
)
}
}
ReactDOM.render(
<B/>,
document.getElementById('root')
)
<div id="root"></div>