我在我的應(yīng)用程序中使用本機(jī)基本輸入字段,如下所示:const [startingPoint, setStartingPoint] = useState('');const [endingPoint, setEndingPoint] = useState('');<Input placeholder="My Input Value" onChangeText={text => setEndingPoint(text)} value={endingPoint}/>這些值包含在 View 和 Modals 中。不是任何形式。輸入功能本身可以正常工作。但是,當(dāng)我退出頁面(如在我的應(yīng)用程序中單擊返回或取消)并返回時(shí),我之前在字段中寫入的值仍然存在。每次退出頁面時(shí)有什么方法可以重置它們嗎?這就是我的模態(tài)的樣子:export const JourneyDetailsPage: React.FunctionComponent<JourneyDetailsPageProps> = ({ toggleShowPage, showJourneyDetailsPage,}) => { const [startingPoint, setStartingPoint] = useState(''); const [endingPoint, setEndingPoint] = useState(''); const [showAvailableTripsPage, setShowAvailableTripsPage] = useState(false); const toggleAvailableTripsPage = () => { setShowAvailableTripsPage(showAvailableTripsPage ? false : true); }; return ( <Modal visible={showJourneyDetailsPage} animationType="slide" transparent={true}> <SafeAreaView> <View style={scaledJourneyDetailsStyles.container}> <View style={scaledJourneyDetailsStyles.searchTopContainer}> <View style={scaledJourneyDetailsStyles.searchTopTextContainer}> <Text onPress={toggleShowPage}> Cancel </Text> <Text> Location </Text> <Text> Done </Text> </View> <View> <Item rounded style={scaledJourneyDetailsStyles.searchField}> <Icon name="map-marker" color="green" /> <Input placeholder="Start" onChangeText={text => setStartingPoint(text)} value={startingPoint}
退出時(shí)重置輸入值
紫衣仙女
2022-07-21 10:36:34