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

248
Visualizações
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 à 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