【发布时间】:2019-01-04 11:48:42
【问题描述】:
我正在尝试通过 props 将值从子组件传递给父组件,其中包含一个函数,但它会引发错误 undefined is not a function(evaluating(this.setstate({search: val})) 请问我做错了什么
class Child extends React.Component {
do() {
this.props.value("books");
}
componentDidMount() {
this.do();
}
render() {
return <Text>yams</Text>;
}
}
class Parent extends React.Component {
constructor(props) {
super(props);
this.state = {
search: ""
};
}
handleChange = e => {
this.props.onUpdate(e.target.value);
this.setState({ search: e.target.value });
};
con(val) {
this.setState({ search: val });
}
render() {
return (
<View>
<Child value={this.con} />
<Text>{this.state.search}</Text>{" "}
</View>
);
}
}
【问题讨论】:
标签: javascript reactjs react-native