S
S
Sanchik972018-10-18 13:22:07
React
Sanchik97, 2018-10-18 13:22:07

How to call another component on click?

Good afternoon! Let's say there is a component A, in which the button is rendered, and a component B, in which the render method returns a modal window. How can I call a modal window from component B by clicking on the button of component A?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-10-18
@Sanchik97

class Parent extends React.Component {
  state = {
    someStateKey: false,
  };
 
  someHandler = () => {
    this.setState({ someStateKey: true });
  };
  
  render() {
    return (
      <Wrapper>
        <ChildA someHandler={this.someHandler} />
        <ChildB stateKey={this.state.someStateKey} />
      </Wrapper>
    );
 }  
}

Lifting state up
I still advise you to master the official Tutorial and documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question