无法在 React 中使用名称中带有破折号的任何 CSS 进行内联 CSS(解析器错误)

sam*_*oul 4 reactjs

如何在 React 中使用属性名称中带有破折号的内联 CSS?

当我这样做时,我的解析器会抛出以下错误:

TS1005:The parser expected to find a '}' to match the '{' token here.

例如:

<div style={{background-color:blue}}/>
Run Code Online (Sandbox Code Playgroud)

Dav*_*vey 9

通常 React 中的内联 CSS 不包含破折号。background-color也会如此backgroundColor

请参见例如使用 CSS 设置 React 样式