TheGreen Lightbulb
TheGreen Lightbulb

Reputation: 163

I am trying to log the props of a parent component in the child component

Im trying to get the props passed to my parent component using this.state.props in my child component.

I have googled everywhere

   choice(){
     console.log(this.props.size);
  }

{this.props.size && <DropdownItem onClick={this.choice} className="bg-info">{this.props.size}</DropdownItem>}


this is the parent component
 <DropDown
                      title="Options"
                      special={special}
                      size={size1}

Upvotes: 1

Views: 36

Answers (1)

brandonwang
brandonwang

Reputation: 1643

Try this:

choice() {
    console.log(this.props.size);
}

{this.props.size && <DropdownItem onClick={() => this.choice()} className="bg-info">{this.props.size}</DropdownItem>}

If you want to change the size each time you click it, you have to use state and not props.

Upvotes: 1

Related Questions