0

Good evening everyone I'm having a hard time manipulating an object of objects. Currently I am using the PancakeSwap API with this API data.

code:

import React, {useState, useEffect} from 'react';
import istancePriceBnb from './pricebnb';
import Listtokenbsc from '../Listtokenbsc';

const Valuetoken = () => {
  const [contractbsc, setContractbsc] = useState ([]);
  useEffect(() =>{
    async function price(){
      try {
    const response=await istancePriceBnb('')
    setContractbsc(response.data.data)
      } catch (err){console.log(err) }
    }
  price()
  }, [])
var newarray= [];
newarray [0] = contractbsc;
  return (
    <div>
{newarray.map( token => {
  return (<Listtokenbsc key={token.id} name={token.name} />)
})}
    </div>
  )
}

export default Valuetoken 
DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127
raziel90
  • 15
  • 6
  • First of all, I think you should check if you are getting the right response from the API. You can console.log the response from the API and see the structure. Also, have a look at the structure of the newarray variable you are mapping. If possible you can explain your problem in more detail so I can focus more in there. Also could you share the newarray console.log and the response.data.data console.log so we can better understand what are you getting. – Martin Dedja May 09 '22 at 14:18
  • Thanks for the reply. doing the console.log (newarray) I get an object array of several objects. I need to display some properties such as price, volume, name etc. here is what i see in the console ` [{0x0B165eD2633E08FE5e778E085e95C1C9b52e300D: {name: 'Flames', symbol: 'FLS', price: '39.0841527768469435086920896587', price_BNB: '0.1197444947579203340470149882282'}}]` – raziel90 May 09 '22 at 14:47
  • Please [edit] this information into the question rather than posting it only in the comments. – Ryan M May 09 '22 at 23:51

0 Answers0