Reactjs 我正在尝试将函数从app.js传递到Deatails屏幕。但我一直收到这个错误(在导航中发现了不可序列化的值)
我在详细信息屏幕中有textinput,当用户单击该按钮时,我想添加用户在第一页的flatlist中输入的文本 这是我的app.jsReactjs 我正在尝试将函数从app.js传递到Deatails屏幕。但我一直收到这个错误(在导航中发现了不可序列化的值),reactjs,react-native,react-hooks,react-navigation,react-native-flatlist,Reactjs,React Native,React Hooks,React Navigation,React Native Flatlist,我在详细信息屏幕中有textinput,当用户单击该按钮时,我想添加用户在第一页的flatlist中输入的文本 这是我的app.js function HomeScreen({ navigation }) { const [Note, setNote] = useState([]); const addNotes = (note) => { note.id == note.length + 1; setNote([...Note, note]); }; ret
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>
功能主屏幕({navigation}){
const[Note,setNote]=useState([]);
常量添加注释=(注释)=>{
note.id==note.length+1;
设置注释([…注释,注释]);
};
返回(
主屏幕
导航。导航(“详细信息”{
补充说明,
})
}
/>
{
{项目.说明};
}}
/>
));
}
这是我的详细信息屏幕
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>
);
}
函数细节屏幕({route,navigation}){
const[notes,setNotes]=useState(“”);
函数Onadd(){
route.params.addNotes({notes});
navigation.goBack();
}
返回(
输入屏幕
{notes}
Onadd()}/>
);
}
您不能在导航中传递函数,只能传递数据。