首页 > 解决方案 > 我正在尝试将函数从 app.js 传递到详细信息屏幕。但我不断收到此错误(在导航中发现了不可序列化的值)

问题描述

当用户单击该按钮时,我在详细信息屏幕中有文本输入和一个按钮,我想添加用户在第一页的平面列表中输入的文本

这是我的 app.js

function HomeScreen({ navigation }) {
  const [Note, setNote] = useState([]);
  const addNotes = (note) => {
    note.id == note.length + 1;
    setNote([...Note, note]);
  };

return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Text>Home Screen</Text>
      <Button
        title="Go to Details"
        onPress={() =>
          navigation.navigate("Details", {
            addNotes,
          })
        }
  />
  <View>
    <FlatList
      data={Note}
      renderItem={({ item }) => {
        <Text>{item.Note}</Text>;
      }}
    />
  </View>
</View>

); }

这是我的详细信息屏幕

function DetailsScreen({ route, navigation }) {
  const [notes, setNotes] = useState("");
  function Onadd() {
    route.params.addNotes({ notes });
    navigation.goBack();
  }
  return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Text>input Screen</Text>
      <View>
        <TextInput value={notes} onChangeText={setNotes} style={styles.input} />
      </View>
      <Text>{notes}</Text>
      <Button title="Go to HomeScreen" onPress={() => Onadd()} />
    </View>
  );
}

标签: reactjsreact-nativereact-hooksreact-navigationreact-native-flatlist

解决方案


推荐阅读