2 回答

TA貢獻1812條經(jīng)驗 獲得超5個贊
如果你使用了 react-navigation,試試這個來訪問導(dǎo)航參數(shù)
componentDidMount() {
const { navigation } = this.props;
// console.log(navigation.state);
const hireId = navigation.state.params.hireId;
const ref = Firebase.firestore().collection('hires').doc(hireId);
ref.get().then((doc) => {
if (doc.exists) {
this.setState({
hire: doc.data(),
key: doc.id,
isLoading: false
});
} else {
console.log("No such document!");
}
});
}
并參考這個類似的問題 https://stackoverflow.com/questions/58279318/navigation-getparam-in-not-an-object/58280498#58280498

TA貢獻1906條經(jīng)驗 獲得超3個贊
this.props.navigation.navigate('PastHireDetails', {
hireId: 12,
})
在上面的行中,您設(shè)置了一個名為hiringId 的導(dǎo)航參數(shù),它是一個整數(shù)
const { navigation } = this.props
navigation.getParam('hireId')
navigation.getParam('hireId') 將返回一個整數(shù)值
但是在另一個腳本中,您可以通過以下方式將該整數(shù)轉(zhuǎn)換為 JSON JSON.parse(navigation.getParam('hireId'))
這會給你一個錯誤
嘗試刪除 JSON.parse 因為它已經(jīng)是您想要的整數(shù)
添加回答
舉報