Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react native pass params to previous screen

function HomeScreen({ navigation, route }) {
  React.useEffect(() => {
    if (route.params?.post) {
      // Post updated, do something with `route.params.post`
      // For example, send the post to the server
    }
  }, [route.params?.post]);

  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button
        title="Create post"
        onPress={() => navigation.navigate('CreatePost')}
      />
      <Text style={{ margin: 10 }}>Post: {route.params?.post}</Text>
    </View>
  );
}

function CreatePostScreen({ navigation, route }) {
  const [postText, setPostText] = React.useState('');

  return (
    <>
      <TextInput
        multiline
        placeholder="What's on your mind?"
        style={{ height: 200, padding: 10, backgroundColor: 'white' }}
        value={postText}
        onChangeText={setPostText}
      />
      <Button
        title="Done"
        onPress={() => {
          // Pass and merge params back to home screen
          navigation.navigate({
            name: 'Home',
            params: { post: postText },
            merge: true,
          });
        }}
      />
    </>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: rotate image javascript base64 
Javascript :: Hexo - Execute Console Commands 
Javascript :: nodejs mysql Getting the number of affected rows 
Javascript :: react three fiber set cursor pointer 
Javascript :: How to write "Hello World" 
Javascript :: .loads with whole json file 
Javascript :: js get data from liocalstorage 
Javascript :: draw image inside canvas width 100% 
Javascript :: nav hover add class and remove using javascript smooth 
Javascript :: javascript code to run colab in background 
Javascript :: json format in .net core 
Javascript :: how to hide javascript code from client 
Javascript :: how to create your own event emitter in javascript 
Javascript :: Randomly getting error 500 in Azure App Service when downloading angularjs template 
Javascript :: angularjs promise .then() to run sequentially inside a for loop 
Javascript :: Prevent the wiping of an Array after routing Angular.js 
Javascript :: AngularJS Form validation transition to valid when some elements are not even touched yet 
Javascript :: Edit parameter in variable with increment/decrement box and save it 
Javascript :: Undefined value document.getElementById 
Javascript :: I have a dataframe with a json substring in 1 of the columns. i want to extract variables and make columns for them 
Javascript :: How to access POST form fields in Express 
Javascript :: nextjs app wdyr 
Javascript :: Variables In Self Invoking Function 
Javascript :: ... Notation In JavaScript 
Javascript :: get longi and long with an adress react 
Javascript :: node-schedule cancel job 
Javascript :: What Is A Closure: Informal Explanation 
Javascript :: Viewing Your React App On Another Device 
Javascript :: nested object data 
Javascript :: magnetic button vanilla js 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =