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

336
Vistas
React Native - trying to extract the data and store in a variable

enter image description hereI am new to react-native. I was trying to access the API using fetch. I was able to print the result on the console but was unable to print on a mobile screen. I have attached the screenshot of the practice code below. [enter image description here][2]

import React from 'react'
import { StyleSheet, Text, SafeAreaView} from 'react-native'

const getMoviesFromApi = () => {
  //GET request
  fetch('https://reactnative.dev/movies.json', {
    method: 'GET',
    //Request Type
    //method: 'POST',
  })
    .then((response) => response.json())
    //If response is in json then in success
    .then((responseJson) => {
      //Success
     // alert(JSON.stringify(responseJson));
      //console.log(responseJson);
      return responseJson;
    })
}

const App = () => {
    let data = getMoviesFromApi()
    console.log(data)

     return (

        <SafeAreaView>
          <Text> JSON.stringify{data} </Text>

          {/* <Text> JSON.stringify{parseData} </Text> */}
        </SafeAreaView>
     )
}

const styles = StyleSheet.create({})

export default App

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You want to use an useState and keep the data you receive from the api inside state, and useEffect to fetch the data when state updates so will the UI

So I would use something like this:

import { useState, useEffect } from 'react';

const App = () => {
  const [movies, setMovies] = useState([]);

  useEffect(() => {
    const fetchMovies = async () => {
      const data = await getMoviesFromApi();
      setMovies(data); // I supose it's an array of movies
    }
  }, [getMoviesFromApi])

  return (...);
}
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