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

119
Vistas
Accessing Object in Object in React

Hello I have a data fetching of Object from Object

Data

    {
  "test1": {
    "success": true,
    "mmr": 1627,
    "name": "Choo",
    "next_claim": 1639454954
  },
  "test2": {
    "success": true,
    "mmr": 1246,
    "name": "Dee",
    "next_claim": 1639454934
  },
  "test3": {
    "success": true,
    "mmr": 1066,
    "name": "Boo",
    "next_claim": 1639454964
  }
}

I can't seem to show them on the page

tried using

import React, { useState, useEffect } from "react"
import Axios from "axios"

const Axie = () => {
  const [axieStats, setAxieStats] = useState({})

  const fetchAxie = async () => {
    const response = await Axios(
      "https://game-api.axie.technology/api/v1/ronin:0d771f9d749fe72671526e0a52ecdfc11f73ca7b,ronin:b9603b5ae4d10fce072432d99de572c1eb66b43e"
    )
    setAxieStats(response.data)
  }

  console.log(axieStats)
  useEffect(() => {
    fetchAxie()
  }, [])
  return <div></div>
}

export default Axie

can't seem to work

I have edited the question to the whole code from where I fetch the API.

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

0

The useState hook as seen in your code is first initialized to an empty object, which is not the desired object you want to use in the first place. When you're trying to access test2.mmr on the empty object test it will not find that object and throw a null reference exception. Here are some things you can do to get to the state you need:

  • Check that you're setting the data using the setTest function somewhere in your code.
  • If the data doesn't exist locally (which is a common occurrence), then the call to fetch the data is asynchronous and you should have a async-await mechanism in place to handle updating the state variables for the dependent components.
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