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

466
Visualizações
Converting array of strings to both JSX Elements and strings in React

I have a tricky one here: I am building a code editor in React that styles different parts of ES6 code. My app works by, converting all the code to one string, then uses Regex to identify where to insert <span>, <strong>, and <br/> tags. I have then taken that long string and used regex with split() to extract all the tags I use into an array. I am now left with this array of strings:

['', '<strong>', 'for', '</strong>', ' (', '<strong>', 'let', '</strong>', ' ', '<span style={{color:"blue"}}>', 'i', '</span>', ' = ', '<span style={{color:"red"}}>', '1', '</span>', '; ', '<span style={{color:"blue"}}>', 'i', '</span>', ' <= ', '<span style={{color:"red"}}>', '10', '</span>', '; ', '<span style={{color:"blue"}}>', 'i', '</span>', '++) {', '<br/>', ',    console.log(', '<span style={{color:"green !important"}}>', '`Pass number ${', '<span style={{color:"blue"}}>', 'i', '</span>', '}`', '</span>', ');', '<br/>', ',}', '<br/>', '']

I need to basically find a way to convert the applicable strings to pure JSX and end up with an array of both strings and JSX.Elements to render out my component. I'm going to take a shower and think, I'm assuming a map of some sort will work??

Appreciate your time and help.

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

0

I ended up going back a step and not converting everything to an Array, and used

 return <div dangerouslySetInnerHTML={{ __html: styledNumbers }}></div>

Works like a charm, for this project. If it was for something public I would likely use this

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