React native React Native Expo:在将价值传递给其他供应商时面临问题
我正在创建一个记事本应用程序。 我有三个屏幕:处理抽屉和堆栈的索引屏幕、所有注释和编辑屏幕。 问题出在Edite屏幕上。我创建文本输入并使用状态进行处理,但当用户单击“添加”按钮(存在editScreen导航)时,我想将该注释添加到所有注释中, 我如何传递值。请帮助我,我是一个初学者 这是app.js中的Edite_屏幕React native React Native Expo:在将价值传递给其他供应商时面临问题,react-native,expo,react-native-android,react-native-flatlist,react-native-navigation,React Native,Expo,React Native Android,React Native Flatlist,React Native Navigation,我正在创建一个记事本应用程序。 我有三个屏幕:处理抽屉和堆栈的索引屏幕、所有注释和编辑屏幕。 问题出在Edite屏幕上。我创建文本输入并使用状态进行处理,但当用户单击“添加”按钮(存在editScreen导航)时,我想将该注释添加到所有注释中, 我如何传递值。请帮助我,我是一个初学者 这是app.js中的Edite_屏幕 const EditeScreene=({navigation,props})=>( ( navigation.goBack()}> ), 头灯:()=>( ), }} />
const EditeScreene=({navigation,props})=>(
(
navigation.goBack()}>
),
头灯:()=>(
),
}}
/>
);
这是我的AllNotes\u屏幕
constallnotes=({navigation,props})=>{
const[NewNotes,setNewNotes]=React.useState([]);
//处理文本输入函数
//交最新的笔记
常数handleNotes=()=>{
setNewNotes([…NewNotes,props.notes]);
};
返回(
navigation.navigate(“Editee”)}
name=“plus”
大小={74}
color=“黑色”
/>
);
})
这是我的编辑屏幕
const EditeScreen=({navigation})=>{
//管理文本输入开始
const[notes,setNotes]=React.useState(“”);
//获取文本输入值
const HandlingTextValut=(输入注释)=>{
设置注释(输入注释);
};
返回(
);
};
在生产应用程序中,最好使用更持久的技术来管理notes状态,比如将其存储在上下文中。然后,您可以从两个屏幕访问该上下文并向其发送操作
不过,对于您发布的代码,一个更快的解决方案是在切换屏幕时将注释作为导航参数传递。然后,您可以从导航
道具访问传递的数据,并对其执行任何操作。如果您查看库中的导航
方法的文档,您可以找到有关此方法的更多信息。您能在我的代码中给出一个示例吗
const EditeScreene = ({ navigation , props }) => (
<Stack.Navigator>
<Stack.Screen
name="homee"
component={EditScreen}
options={{
title: "Edite Screen",
headerTitleStyle: {
textAlign: "center",
},
headerLeft: (props) => (
<TouchableOpacity onPress={() => navigation.goBack()}>
<AntDesign
name="back"
size={30}
color="red"
style={{ margin: 10 }}
/>
</TouchableOpacity>
),
headerRight: () => (
<TouchableOpacit onPress={}>
<MaterialIcons name="done" size={34} color="black" />
</TouchableOpacit>
),
}}
/>
</Stack.Navigator>
);
const AllNotes = ({ navigation , props}) => {
const [NewNotes, setNewNotes] = React.useState([]);
// handling textinput function
// handing Updated Notes
const handleNotes = () => {
setNewNotes([...NewNotes, props.notes]);
};
return (
<View style={styles.container}>
<View style={styles.searchInput}>
<MaterialIcons
name="search"
size={22}
style={styles.searchIcon}
color="#bbb"
/>
<TextInput
style={styles.inputText}
placeholder={"I'm looking for..."}
placeholderTextColor={"#999"}
underlineColorAndroid={"#fff"}
autoCorrect={false}
onChangeText={AddNotes}
value={notes}
/>
</View>
<ScrollView>
<View style={styles.notesContainer}>
</View>
</ScrollView>
<View style={styles.plusContainer}>
<EvilIcons
onPress={() => navigation.navigate("Editee")}
name="plus"
size={74}
color="black"
/>
</View>
</View>
);
const EditeScreen = ({ navigation }) => {
// manges textInput starts
const [notes, setNotes] = React.useState("");
//getting text input value
const HandlingTextValut = (EnteredNotes) => {
setNotes(EnteredNotes);
};
return (
<ScrollView>
<View style={styles.InputContainer}>
<TextInput
style={styles.inputText}
placeholder={"Take Notes ..."}
onChangeText={HandlingTextValut}
value={notes}
/>
</View>
</ScrollView>
);
};