reactjs - 我正在尝试将函数从 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>
);
}
解决方案
推荐阅读
- docker - Docker 预构建镜像 delpoy 到 Heroku
- sql - 在 SQL 中将相应的列插入到更大的表中
- javascript - sql 查询可以因列而异吗?
- python - 使用 PYTHON 放置在循环中时,计数返回零
- web - 是否有带有 DRM 的开源视频平台?
- puppeteer - PuppeteerSharp:无法启动 Chromium
- c++ - 是什么导致继承和成员之间结构大小的差异?
- node.js - 获取 sftp 服务器的所有支持的 KexAlgorithms
- api - 隐藏从提琴手或其他应用程序获取请求的请求/响应标头
- amazon-web-services - CloudWatch 规则不会触发 Lambda 函数,即使具有正确的权限