Passing a child component as prop when that child needs to trigger parent's state?

I have a modal that is opened by a button click. I want to use it in different places with different types of buttons. I understand I can pass components into the parent, but what about when those components need to trigger the parent’s state?

const modalButtonOne = () => (
<CircleButton />

const modalButtonTwo = () => (
<SquareButton />

export class Modal extends React.Component {

   constructor(props) {
    this.handleClose = this.handleClose.bind(this);
    this.handleOpen = this.handleOpen.bind(this);
    this.state = {
      open: false,
handleOpen() {
    console.log('this ran')
    this.setState({open: true});

handleClose() {
    this.setState({open: false});
return <div>

( of course the modal component above is a stateless component for brevity, but imagine its an es6 class with a state object that has a ‘open boolean’)

Then I could have a modal that is triggered by either a circle button or a square button:

  modalButton={<CircleButton onTouchTap={this.handleOpen} />} 

but how to I have 's onClick trigger the ‘open’ state of the parent modal?

The parent already has that child prop!

If the child has a prop, then it is because its parent provided that prop to the child! Why do you want the child to pass back the prop to the parent, while the parent obviously already has that prop?

1 Like


You can do some really cool stuff with passing around child components. See There’s nesting upto 3 levels, and props are ‘managed’ only once.

I updated my pseudo code to better explain.

I need the buttons to trigger this.handleOpen

These are exactly the things React takes care of for you. See and

Here’s a simple example of what you want done.

class Parent extends React.Component {
  constructor(props) {
    this.handler = this.handler.bind(this)

  handler(e) {
      someVar: someValue

  render() {
    return <Child handler = {this.handler} />

class Child extendes React.Component {
  render() {
    return <Button onClick = {this.props.handler}/ >

PS: For you, the child is the Square or Circle button and the parent is the modal.

I hope that helps.