-
Notifications
You must be signed in to change notification settings - Fork 659
-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Append content to body tag attributes via Helmet #365
Comments
Isn't this creeping beyond the scope of react-helmet? Helmet i.e. head? |
+1 |
While react-helmet does not support appending classes, you can simply add new attributes to your body tag. Then use those attributes as selectors. E.g.: <App>
<Helmet>
<body data-first="true" />
</Helmet>
<Helmet>
<body data-second="true" />
</Helmet>
</App> The output will be: <body data-first="true" data-second="true" /> Then use attribute selectors: body[data-first] {
color: blue;
}
body[data-second] {
color: red;
} |
We have a 3rd party script adding classes to the body tag, but Helmet is overwriting them . Why is appending classes not supported? |
The typical and recommended approach is to not wrap the entire body but to use helmet as a sibling to the body. ie
https://github.com/nfl/react-helmet#as-react-components I could be misunderstanding the issue, let me know if that helps. |
@tmbtech We're using react strictly client side, and Helmet to add some data attributes and update className='...' to an existing body tag. |
@Noyabronok can you provide an example via https://codesandbox.io |
bump!!! Edit:
|
@bittu This task was for a former project but I heard they made quite a bit of progress with this in our UI platform by using https://github.com/staylor/react-helmet-async . |
@jeffredodd Ah ok... https://github.com/staylor/react-helmet-async is this package for SSR only or client-side rendering as well? |
Hello all, I am looking for placing a noscript snippet within body. Is there a way to achieve this with react-helmet? Thank you in advance |
Any updates? Still actual. |
Closing as React has changed a ton in 4 years and this is not a good proposed solution. Plus this repo hasn't received updates in a while. |
When using react Helmet, I would like a way to append content into my attributes onto my
<body>
tag.For example this code will set my body class ...
JSX
Output
<body class='first-class'>
And when I have a component deeper in my application call helmet like such the body class is overwritten...
JSX
Output
<body class='second-class'>
Desired Output
<body class='first-class second-class'>
Currently the fix for this in my application is to call the following which is not sustainable as we now have to maintain many body classes throughout our application...
JSX
Potential Solution
In order to set this up correctly you cannot call class but maybe using something like the following would be an appropriate way to append an item to helmet as calling class directly should still overwrite class so that a breaking change is not introduced to helmet?
JSX
The text was updated successfully, but these errors were encountered: