Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

202
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda