Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
fetch data is providing some [assets] and [objects]. How can I de-structure these in the following code in order to list them out?

This is the data I'm receiving:

{
      market_contract: 'atomicmarket',
      assets_contract: 'atomicassets',
      sale_id: '278354',
      seller: 'stexpr',
      buyer: null,
      offer_id: '280670',
      price: [Object],
      listing_price: '5000000',
      listing_symbol: 'XUSDC',
      assets: [Array],
      maker_marketplace: 'protonmint',
      taker_marketplace: null,
      collection_name: '355532155243',
      collection: [Object],
      is_seller_contract: false,
      updated_at_block: '116895433',
      updated_at_time: '1646077501500',
      created_at_block: '116895433',
      created_at_time: '1646077501500',
      ordinality: '58',
      state: 1
}

This is the code I'm using to list some of the items out:

  const res = await fetch(
    'https://proton.api.atomicassets.io/atomicmarket/v1/sales'
  );
  const data = await res.json();
  return {
    props: {
      data,
    },
  };
}

function UserTransactions({ data }) {
  const results = data;
  console.log(results);
  return (
    <PageLayout>
      <div>This is a list of User Transactions!</div>
      <ul>
        {results.data.map((result) => {
          const { sale_id, buyer, seller, assets } = result;

          return (
            <li key={data.id}>
              <h3>
                {seller} just sold {sale_id} to {buyer} for{' '}
              </h3>
              <img src={assets} alt={sale_id} />
            </li>
          );
        })}
        <li></li>
      </ul>
    </PageLayout>
  );
}

export default UserTransactions;

I'm able to create list items of sale_id,buyer, and seller just fine. Assets, on the other hand, does not work. What can I do to make it list out?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Assumptions from unclear parts of the question:

  • assets is an array of strings, where each string is an image URL.
  • You wanted 1 <li> per asset per result, not 1 <li> per result.

Then it will not be enough to have one .map(...). You need an inner map over each result's assets array. Then the outer map can change to be a .flatMap(...) so that it "flattens" the inner map's individual arrays into a single array of <li> items.

{results.data.flatMap((result) => {
    const { sale_id, buyer, seller, assets } = result;

    return assets.map((asset) => (
        <li key={sale_id + '|' + asset}>
            <h3>
                {seller} just sold {sale_id} to {buyer} for{' '}
            </h3>
            <img src={asset} alt={sale_id} />
        </li>
    ));
})}

Note have I have also changed the list element key= so that it uniquely refers to the identity of the listed data.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda