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

123
Views
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 answers
Answer question

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 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!