React Native :undefined不是对象(评估'route. params')

xmjla07d  于 2022-11-17  发布在  React
关注(0)|答案(1)|浏览(167)

undefined不是一个对象(评估“route. params”)是错误代码,但我不知道如何修复它...

Screen1:

function Screen1({ navigation }) {

  return (

between return and onPress are some components

   onPress={() =>
                navigation.navigate("Screen2", {
                  title: "Beispiel Titel",
                  author: "Beispiel Author",
                  genre: "Beispiel Genre",
                })

画面二:

function BookDetailScreen({ route, navigation }) {
  const { title, author, genre } = route.params;

有人能帮忙吗?谢谢!:)
我想将参数从屏幕1提供给屏幕2

j0pj023g

j0pj023g1#

有时react-navigation在第一次渲染时没有填充route对象。

const { title, author, genre } = route?.params;

或者

const { params } = route || { title: 'default title', author: 'default author' }; // etc

相关问题