Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to redirect from axios in react native

i am trying to redirect in react native am new to reactnative can anyone help me with this

 axios.post('http://10.0.2.2:8000/client/user', Data)

      .then(() => {
        //if succcess redirect to another url and pass data to that url
      })

      .catch(error => {
        alert(error);
      });
  }

i want to another to a url and pass data to that url when .then is executed

is this the correct method to pass this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<PaperProvider>
        <NavigationContainer>
          <Stack.Navigator>
            <Stack.Screen
              options={{headerShown: false}}
              name="Home"
              component={HomeScreen}
            />
           
            <Stack.Screen name="Home_scrren" component={Home_scrren} />
            <Stack.Screen name="Pregnant" component={Pregnant} />
          
          </Stack.Navigator>
        </NavigationContainer>
      </PaperProvider>

>Solution :

This is how you can navigate if API is successful

axios
  .post("http://10.0.2.2:8000/client/user", Data)

  .then((res) => {
    //if succcess redirect to another url and pass data to that url
    if (res.status == 200) {
      props.navigation.navigate("Pregnant", { data: res.data });
    } else {
      // show alert or your logic
    }
  })

  .catch((error) => {
    alert(error);
  });

And this is how you can get data from the another screen:
Read more on this

useEffect(() => {
  console.log("route.params ==>", props.route.params);
}, []);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading