我有一个将数据传递给父组件的子组件,但我必须在数据上单击 3 次才能使 setState 成功,但我不知道如何制作以便它仅在以下情况下调用父函数状态设置成功,下面是我的代码:
子函数:
onSelection =(nodeKey, node) =>{
if(nodeKey.target.localName === "svg")
{
return;
}else
{
this.setState({selection: node},
this.props.setSelectedValue(this.state.selection)); //returns data to parent component
}
}
父母:
setSelectedValue = data =>{
this.setState({selection: data});
}
答案 0 :(得分:0)
您可以使用箭头函数来做到这一点。就像下面的代码。
SHOW TAG VALUES WITH KEY = "hostname"