Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Run API requests sequentially in react native?

Looking for the best way to accomplish the following.

The goal is to, when this screen loads:

  1. Retrieve the user's auth token from async storage, THEN
  2. Hit an API with the auth token to grab some user details (in this case userId)

I'm also trying to useEffect so these only run once.

Function 1:

const getUserToken = async () => {
      try {
        const userToken = await AsyncStorage.getItem("userToken", userToken);
        setUserToken(userToken);
      } catch (err) {
        console.log("err retrieving token " + err);
      }

Function 2:

const getUserId = async () => {
      try {
        let response = await xano.get("/auth/me", {
          headers: { Authorization: userToken },
        });
        setUserId(response.data.id);
        console.log(userId);
      } catch (err) {
        console.log("getUserId err " + err);
        console.log(err.data);
      }
    };

Function 3:

 useEffect(() => {
    getUserToken();
getUserId();

  }, []);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to await those async functions in the useEffect hook.

useEffect(() => {
    async function fetchMyAPI() {
      await getUserToken();
      await getUserId();      
    }
    fetchMyAPI();
}, [])  
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!