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

295
Views
How to write CSS / SCSS / PostCSS inside React .tsx file as JavaScript String in VSCode and WebStorm?

I am trying to set up a new self convention to make my React code better organized like the following:

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

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

It works fine, but writing the return in getStyle() is pretty hard because I don't get formatting or syntax highlight help from the IDE.

How can I get those? Plugin / Library / Setting / Giving it a type? Any of those will help.

And at the same chance, do you think this can cause any issues down the road?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

In vscode you can use ES6 String css vscode extension

Just add /*css*/ before ` like this

function getStyle() {
  return /*css*/`
        h1 {
          color: blue;
        }
      `
}
over 4 years ago · Santiago Trujillo Report

0

WebStorm has a built-in feature Language Injection. for that.

Here you will find in detail documentation of that feature.

Short version.

  1. Place your cursor in the relevant code block and click alt + enter.

enter image description here

  1. In the DropDown, select Inject language or reference. Without clicking to the right, click enter again.

enter image description here

  1. A window should open, now select the language you like to inject. If you select CSS the result should be:

enter image description here

To answer your second question. It shouldn't cause any trouble down the road.

edit addition:

It is possible to trigger the same behaviour with a comment laguange=css

enter image description here

over 4 years ago · Santiago Trujillo Report
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!