感觉就像我的问题是非常简单的,但我不知道为什么它不工作。反应孩子JSX元素不从父母继承此
为什么我想要做的是基本的东西 - 我从父母到孩子传递一个函数,它应该增加父母的“测试”值为1的值(这只是一个概念证明)。问题发生在调用父函数时。 。我收到“无法读取的未定义的属性测试”在调试器this.props也是不确定的,所以毫不奇怪,this.props.test将是我缺少的是
父:?
export default class GameList extends Component {
constructor({ navigation }) {
super();
this.state = {
test: 0,
}
};
updateState() {
this.setState({
test: this.state.test++,
});
}
render() {
return (
<View style={styles.background}>
<Header updateState={this.updateState} />
</View >
)
}
}
儿童:
import React, { Component } from 'react';
import { View, TextInput } from 'react-native';
import styles from './styles';
class Header extends Component {
render() {
return (
<View style={styles.container}>
<TextInput
style={styles.input}
placeholder="Search..."
onChangeText={(text) => {
this.props.updateState();
}}
/>
</View>
);
}
filterRows(searchText, dataSet) {
return dataSet.filter((record) => record.title.includes(searchText));
}
}
export default Header;
沿着'++':)的好传 – Icepickle