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

209
Visualizações
How to add additional information to an array based on dynamic values in ReactJS

I'm trying to add a little tracking component that brings in a tracking number and carrier from an array. From there, it should add a url to the carrier website. I need to add an if statement or something so when it sees a specific carrier, it adds the url but I'm struggling.

renderTrackingNumbers() {
    const { order: { tracking_info } } = this.props;

    const trackingNumbers = tracking_info.map((tracking_info) => (
        <div key={ tracking_info.id }>
            <a href="{ tracking_url_should_be_added_here }">{ tracking_info.tracking_number }</a>
            { ' ' }
            -
            { ' ' }
            { tracking_info.carrier_code }
        </div>
    ));

    return (
        <div>
            <h4>{ __('Tracking Numbers') }</h4>
            <div>
                { trackingNumbers }
            </div>
        </div>
    );
}

Here is the data I'm receiving from GraphQL:

[
{
    "tracking_number": "231300687629630",
    "carrier_code": "fedex"
},
{
    "tracking_number": "1234567890",
    "carrier_code": "dhl"
},
{
    "tracking_number": "1Z12345E0305271640",
    "carrier_code": "ups"
},
{
    "tracking_number": "123465789123456",
    "carrier_code": "usps"
}
]

Any help would be awesome.

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

0

Try to map the array like this

arr.map(i=>{return {
    ...i ,
    url:i.carrier_code==='fedex'?'www.fedex.com':
                           i.carrier_code==='dhl'?'www.dhl.com':'you name it'}}
)

and when you loop through this it would be like :

<a href="{i.url }">...</a>
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