简体   繁体   中英

React Native navigation on successful api response

just wanted to ask about the possible ways to navigate to a screen upon a successful api response in react native.. I have been using redux for state management in projects.

I have tried a few ways and would like suggestions of good practice from you all.

  1. using useEffect hook with a dependency.
  2. passing the navigation object in the action and call it on the successful.then result.
  3. using promises like
let promise = new Promise(function(resolve, reject) {
  setTimeout(() => resolve("done!"), 1000);
//api call here
});

promise.then(
  result => alert(result), //navigation login
  error => alert(error) // error handling
);

use useNavigation hooks to navigate to a particular screen.

const navigation = useNavigation();

let promise = new Promise(function(resolve, reject) {
  setTimeout(() => resolve("done!"), 1000);
//api call here
});

promise.then(
  result => navigation.navigate('OtherScree',{
  result:result}), //navigation login
  error => alert(error) // error handling
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM