Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

462
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda