我正在尝试在子组件中记录父组件的道具

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

我试图在我的子组件中使用 this.state.props 将 props 传递给我的父组件。

我到处搜索

   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}

试试这个:

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

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

如果您想在每次单击时更改大小,则必须使用 state 而不是 props