Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Can';在react native中将状态值从子组件传递到父组件_Reactjs_React Native - Fatal编程技术网

Reactjs Can';在react native中将状态值从子组件传递到父组件

Reactjs Can';在react native中将状态值从子组件传递到父组件,reactjs,react-native,Reactjs,React Native,我想在父组件中使用子组件内部的状态。以下是我的组件的设置方式: 儿童: export default class Child extends React.PureComponent { constructor() { this.state = { value: "123", }; } updateValue(data){ this.props.updateValue(data); } componentWillMount(){ this.up

我想在父组件中使用子组件内部的状态。以下是我的组件的设置方式:

儿童:

export default class Child extends React.PureComponent {
  constructor() {
    this.state = {
      value: "123",
    };
  }
updateValue(data){
    this.props.updateValue(data);
}

componentWillMount(){
    this.updateValue(this.state.value);
}
}
家长:

export default class Parent extends Component {
    constructor() {
    super(props)
    this.state = {  
        newValue: ""
    };
  }

updateState (data) {
        this.setState(newValue: data);
    }
  render() {
return(
        <Child updateValue={this.updateState.bind(this)}/>
)
}
}
导出默认类父扩展组件{
构造函数(){
超级(道具)
this.state={
新值:“
};
}
房地产(数据){
此.setState(新值:数据);
}
render(){
返回(
)
}
}

然而,它似乎不起作用,给了我一个错误。我做错什么了吗?

记住
this.setState
需要一个参数。您传递了一个未存储在数据结构中的key:value对

this.setState(newValue: data);
应该是

this.setState({newValue: data});

错误会说什么?
this.setState(newValue:data)
不是有效的对象-应该是
this.setState({newValue:data})它准确地告诉你出了什么问题。字面上