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

244
Vistas
How to format and return <style jsx> string from a function in React or Nextjs

I am trying to find a way to "organize" react component like vue, where it's bundled together with different section for HTML, JS and CSS.

For example

export default function HeaderExample() {
  return (
    <>
      <h1>Hello World</h1>
      <style jsx>{`
        h1 {
          color: yellow;
        }
      `}
      </style>
    </>
  )
}

I want to convert to:

export default function HeaderExample() {
  const compStyle = getStyle();
  return (
    <>
      <h1>Hello World</h1>
      <style jsx>{compStyle}
      </style>
    </>
  )
}

function getStyle() {
  return `
        h1 {
          color: yellow;
        }
      `
}

It does work, but writing it is pretty hard because there is no syntax highlight or anything.

Is that a good convention in general?

And is there a way to enable syntax highlight / formatting help for this type of thing? And should it also work with SCSS or PostCSS?

about 4 years ago · Juan Pablo Isaza
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