oxc-project/oxc · error · OxcDiagnostic
`style` prop value must be an object.
Error message
`style` prop value must be an object.
What it means
Raised by react/style_prop_object when the `style` prop on a JSX element or createElement call is not an object expression — e.g. a string like `style="color:red"` or an identifier that resolves to a non-object. At the throw site React requires style to be an object of CSS properties; string styles (an HTML habit) are rejected at runtime with a warning, so the code is broken as written. run() validates the style prop's expression (following variable declarations via get_declaration_of_variable) and reports non-object values.
Source
Thrown at crates/oxc_linter/src/rules/react/style_prop_object.rs:24
},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_str::CompactStr;
use schemars::JsonSchema;
use serde::Deserialize;
use crate::{
AstNode,
ast_util::get_declaration_of_variable,
context::{ContextHost, LintContext},
rule::{DefaultRuleConfig, Rule},
utils::is_create_element_call,
};
fn style_prop_object_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("`style` prop value must be an object.").with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct StylePropObject(Box<StylePropObjectConfig>);
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct StylePropObjectConfig {
/// List of component names on which to allow `style` prop values of any type.
allow: Vec<CompactStr>,
}
impl std::ops::Deref for StylePropObject {
type Target = StylePropObjectConfig;
fn deref(&self) -> &Self::Target {
&self.0
}View on GitHub (pinned to e1e7af627c)
Solutions
- Convert the string to a style object: style={{ marginTop: 10 }}.
- For raw CSS strings, use a class or a library that accepts strings (e.g. styled-components).
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/style_prop_object.rs:24 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/f0692e2916727ae3.
Report an issue: GitHub.