Skip to main content
Skip to Content
interlace
Plugin: react-featuresRules

style-prop-object

Enforce style prop value is an object

Next step

style-prop-object ships in eslint-plugin-react-features, with 11 of its 68 rules in the recommended preset.

Install
npm install -D eslint-plugin-react-features
eslint.config.js
import { configs } from 'eslint-plugin-react-features';

export default [configs.recommended];

Plugin pagenpmSource on GitHub

React's style prop takes an object of CSS properties. A string, number or boolean throws at render time. This rule is part of eslint-plugin-react-features and follows eslint-plugin-react/style-prop-object in behaviour and options. Its upstream test cases (eslint-plugin-react 7.37.5, MIT) run against it: 70 of 70 agree.

Quick Summary

AspectDetails
SeverityError (correctness)
Auto-Fix❌ No auto-fix
CategoryReact
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForAll React/JSX projects

Rule Details

<div style="color: red" /> is HTML. In React it throws The style prop expects a mapping from style properties to values, not a string. The rule reports a style attribute that is a string, or a braced literal that is not null, and a style value that resolves to one through a const/let declared in the file. The same applies to the style key of the props object in React.createElement(type, props), however createElement is imported.

Nothing else is reported: an identifier the rule cannot trace to a literal (a parameter, an import, a call result), a template literal and null/undefined are left alone.

Examples

❌ Incorrect

<div style="color: red" />

<div style={true} />

const styles = 'color: red';
<div style={styles} />

React.createElement('div', { style: 'color: red' });

✅ Correct

<div style={{ color: 'red' }} />

const styles = { color: 'red' };
<div style={styles} />

<div style={props.styles} />

<div style={null} />

React.createElement('div', { style: { color: 'red' } });

Options

OptionTypeDefaultDescription
allowstring[][]Component names whose style prop is not an object: <Hello style="x" /> and createElement(Hello, {...}) pass
'react-features/style-prop-object': ['error', { allow: ['MyComponent'] }]

When Not To Use It

When every style prop in the project is passed to a component that turns a string into an object. Name those components in allow first.

Use this rule

npm install -D eslint-plugin-react-features
eslint.config.js
import reactFeatures from 'eslint-plugin-react-features';export default [  {    plugins: { 'react-features': reactFeatures },    rules: {      'react-features/style-prop-object': 'error'    },  },];
npm install -D oxlint-plugin-react-features
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-react-features"],  "rules": {    "react-features/style-prop-object": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-react-features'],    rules: {      'react-features/style-prop-object': 'error',    },  },});

oxlint-plugin-react-features re-exports eslint-plugin-react-features/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.