Skip to content

Instantly share code, notes, and snippets.

@DoganM95
Created June 1, 2024 04:13
Show Gist options
  • Save DoganM95/e4ef950385e75a73162bcefe70336b53 to your computer and use it in GitHub Desktop.
Save DoganM95/e4ef950385e75a73162bcefe70336b53 to your computer and use it in GitHub Desktop.
CSS to React inline style conversion using VSCode Regex Replacer

Intro

CSS has a different syntax than react's inline css, which this regex pattern aims to solve by transforming it (right side only).
CSS also kebap-case sytnax and react uses camelCase, making a direct usage of default css unusable (left side).
The current regex only fixes the right side, kebap to camel part needs to be done manually for now. Example

CSS

div {
    overflow-wrap: break-word;
}

React

<div style={{overflowWrap: "break-word"}}></div>

Regex pattern

Search

(:\s)(.*)(;)

Replace with

:"$2",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment