1

did any one had this situation where you should replace an existing component with totally a different one - like an accordian.

<ComponentA /> (+ image) - click on this
<ComponentB /> (- image) - 

Should I use states here? And Should I be having separate images on each component, but how to deal with positioning the images exactly at same location. Any simple example on how to communicate between such components would be helpful.Thanks.

1
  • You can make use of router as well Commented Nov 7, 2016 at 4:13

1 Answer 1

1

yes you need to use states to manipulate the visibility of components. in your render function you could do something like this

render(){
    return this.state && this.state.showComponent1 ? <ComponentA /> :<ComponentB />
}

and in your button onClick event you could set it up like this

onClick = () => this.setState({showComponent1: !this.state.showComponent1})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.