我正在尝试访问传递给本机组件的道具,但该组件似乎未收到道具。传递 props(PastHires.js) 的组件:
return (
<ScrollView style={styles.container}>
<Text style={styles.heading}>Past Hires</Text>
{
this.state.boards.filter(item => item.driverId === this.props.user.id && item.hireStatus === 'completed' ).map((item, i) => (
<ListItem
style={styles.listItem}
key={i}
title={item.pickupDatetime + ' ' + item.hireType.toUpperCase() + ' ' + item.pickupLocation.toUpperCase()}
leftIcon={{name: 'book', type: 'font-awesome'}}
onPress={() => {
this.props.navigation.navigate('PastHireDetails', {
hireId: 12,
});
}}
/>
))
}
</ScrollView>
);
}
接收道具的组件(PastHireDetails.js):
componentDidMount() {
const { navigation } = this.props;
// console.log(navigation.state)
const ref = Firebase.firestore().collection('hires').doc(JSON.parse(navigation.getParam('hireId')));
ref.get().then((doc) => {
if (doc.exists) {
this.setState({
hire: doc.data(),
key: doc.id,
isLoading: false
});
} else {
console.log("No such document!");
}
});
}
这会引发语法错误:JSON Parse Error: Unexpected identifier "undefined" When I console log navigation.state 它返回该参数未定义
Object {
"key": "PastHireDetails",
"params": undefined,
"routeName": "PastHireDetails",
}
我在这里做错了什么吗?任何修复?
ABOUTYOU
一只名叫tom的猫
相关分类