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.
npm install -D eslint-plugin-react-featuresimport { configs } from 'eslint-plugin-react-features';
export default [configs.recommended];
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
| Aspect | Details |
|---|---|
| Severity | Error (correctness) |
| Auto-Fix | ❌ No auto-fix |
| Category | React |
| ESLint MCP | ✅ Optimized for ESLint MCP integration |
| Best For | All 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
| Option | Type | Default | Description |
|---|---|---|---|
allow | string[] | [] | 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-featuresimport 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{ "jsPlugins": ["oxlint-plugin-react-features"], "rules": { "react-features/style-prop-object": "error" }}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.