Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Well, in the parent component, render the second component, throw props to it. What doesn't work?
class Parent extends React.Component {
state = { c2: null }
comp2state = state => { this.setState({ c2: state }) }
return (
<>
<ComponentOne c2state={this.state.c2} />
<ComponentTwo onStateChange={this.comp2state} />
</>
)
}
class ComponentTwo extends React.Component {
state = { bla: '' }
onChange = e => {
this.setState(
{ bla: e.target.value },
() => this.props.onStateChange(this.state)
)
}
return (
<input value={this.state.bla} onChange={onChange} />
)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question