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

172
Vistas
React native, state not defined in useSelector after fetch

I am trying to load data for my component in useEffect. How can I ensure the state is defined before I go to the next screen?

  const [rescueMeContent, setRescueMeContent] = useState({});

  useEffect(() => {
    async function fetchData() {
      const { payload } = await get('xxx');
      setRescueMeContent(payload);
    }
    fetchData();
  });

When I first run the app, on the next screen when I try and access the state like this I get an error saying its undefined:

  const {
    content: {
      splashScreen: {
        backgroundImage: { url },
        buttonText,
        informationText,
        title: pageTitle,
      },
    },
  } = useSelector((state) => state);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

useState works in inside only component. You can't reach that from other component. You must use react redux for to use useSelector. You must assign your fetch data to redux state with action. Then you can get that data with useSelector.

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