0
我是新來的反應本地人,我很奇怪,爲什麼我會收到類似這樣的錯誤不確定是不是一個對象。我試圖添加第二個屏幕上的按鈕按下登錄.js反應本土不確定是不是一個對象
但我不能啓動應用程序原因未定義不是一個對象指向這裏const {navigate} = props.navigation;
謝謝你們
這裏是我的代碼
const login = (props) => {
const { navigate } = props.navigation;
return (
<View style={styles.container}>
<View style={styles.img}>
<Image source={require('./download.png')} />
</View>
<View style={styles.but}>
<Button
onPress={() => navigate ('QR')}
title="Sign in"
color="#2f4f4f"
/>
</View>
</View>
);
}
login.navigationOptions = {
title: 'Login',
};
export default login
這裏是我的index.android.js
export default class Task extends Component {
render() {
const { navigation} = this.props;
return (
<Login navigation={navigation }/>
)
}
}
const SimpleApp = StackNavigator({
Home: {screen: Login},
SecondScreen: {screen: QR}
});
如果刪除const {navigate} ...行並刪除onPress事件處理程序,會發生什麼情況? –
const {navigate} = props.navigation; 這種說法是試圖訪問導航對象和導航的導航屬性來定義,請登錄它檢查你的道具,看看,如果它甚至有導航屬性(我不認爲它有) –
@JanPeter如果我刪除按鈕不會工作。我試過 – kurokocrunch