Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!