Body style attribut is not set properly
Author: testerezCreated Jan 4, 2018Updated May 19, 2026
When trying to set <body> style attribute like this:
<Helmet>
<body style={{background: 'black'}}/>
</Helmet>It is actually set to <body style="[object Object]"/>
I figured out that I need to pass style attribute as a string to make it work:
<Helmet>
<body style="background: black"/>
</Helmet>This is working in the browser but for SSR I get this error:
The
styleprop expects a mapping from style properties to values, not a string.
Here is how I use helmet for SSR:
const Html = ({children}) => {
const helmet = Helmet.rewind();
return (
<html lang="en" {...helmet.htmlAttributes.toComponent()}>
<body {...helmet.bodyAttributes.toComponent()}>
{children}
</body>
</html>
)
}Am I missing something?
Source: nfl/react-helmet