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

263
Visualizações
React: if link contain a domain add a variable

I'm building a web app in ReactJS where I need to show a few links.

Some of this links should end width a ID code and others with others

Example:

https://www.example.com/lorem&[ID-CODE1]
https://www.other.com/lorem&[ID-CODE2]
                                    

I need to do this just for 2 different domains.

My code is something like this:

link={type.content?.url}

But should be

link={type.content?.url}&[ID-CODE1] or &[ID-CODE2]

I hope this explanation do not sound too cryptic and you guys and girls could help me with this, please

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

0

Do you mean something like this?

function constructURLQuery(url, code) {
   return `${url}/?lorem&id=${code}`
}

const LinkComponent = (props) => (
  <a href={props.link} title={props.title}>{props.link}</a>
)

const ListComponent = (props) => (
  <ul>
  {props.links.map(({ id, title, url, code }) => (
    <li key={id}>
      {title}: <LinkComponent link={constructURLQuery(url, code)} title={title}/></li>
   ))}
  </ul>
)

const links = [
  { id: 1, title: 'example', url: 'https://www.example.com', code: '[ID-CODE1]' },
  { id: 2, title: 'other',  url: 'https://www.other.com' , code: '[ID-CODE2]'},
]

const App = (<ListComponent links={links} />)

ReactDOM.render(
  App,
  document.getElementById("app")
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

<div id="app"></div>

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