admin管理员组文章数量:1324837
This should be a fairly simple situation but I'm not having success with it. Using React Navigation v6 (React Native)
I have a modal which I'm navigating to via navigation.navigate()
. It's a modal, so it can be closed by swiping down. The client wants the values from the modal to be passed back to the calling screen. However I can't see a way to do that because I am not calling goBack()
.
Thanks.
This should be a fairly simple situation but I'm not having success with it. Using React Navigation v6 (React Native)
I have a modal which I'm navigating to via navigation.navigate()
. It's a modal, so it can be closed by swiping down. The client wants the values from the modal to be passed back to the calling screen. However I can't see a way to do that because I am not calling goBack()
.
Thanks.
Share Improve this question asked Jan 12 at 7:16 Shawn LauzonShawn Lauzon 6,2824 gold badges36 silver badges47 bronze badges 1- Could you please provide some code snippet? – Jatin Bhuva Commented Jan 13 at 10:07
1 Answer
Reset to default 0You can pass a callback function to the modal through the navigation params.
// Parent Screen
import React, { useState } from "react";
import { View, Button, Text } from "react";
const ParentScreen = ({ navigation }) => {
const [value, setValue] = useState("");
const handleValueChange = (newValue) => {
setValue(newValue);
};
return (
<View>
<Text>Selected Value: {value}</Text>
<Button
title="Open Modal"
onPress={() =>
navigation.navigate("ModalScreen", { onValueChange: handleValueChange })
}
/>
</View>
);
};
export default ParentScreen;
// Modal Screen
import React from "react";
import { View, Button } from "react";
const ModalScreen = ({ route, navigation }) => {
const { onValueChange } = route.params;
const passValueBack = () => {
onValueChange("Value from Modal");
};
return (
<View>
<Button title="Pass Value Back" onPress={passValueBack} />
</View>
);
};
export default ModalScreen;
本文标签: Passing values back from modal using React NavigationStack Overflow
版权声明:本文标题:Passing values back from modal using React Navigation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742120820a2421685.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论