Skip to content
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 #161

Open
slorber opened this issue Mar 17, 2022 · 2 comments
Open

Feature Request: Append content to body tag attributes via Helmet #161

slorber opened this issue Mar 17, 2022 · 2 comments

Comments

@slorber
Copy link
Contributor

slorber commented Mar 17, 2022

This is basically a request for the same feature that was requested in the original repo (nfl/react-helmet#365) and is unlikely to be implemented here.

<>
	  <Helmet>
	    <body className='first-class' />
	  </Helmet>
	  <Helmet>
	    <body className='second-class' />
	  </Helmet>
</>

Should lead to <body className='first-class second-class'> and not <body className='second-class'>

I was wondering if this is something that could be implemented or if we should find another userland solution to handle that.

I can probably have multiple layers of <ApplyHtmlClassName> components, but if I can avoid it's better

@jafin
Copy link

jafin commented Apr 11, 2022

Wouldn't this be out of scope for a component that's role is to amend the head of a dom?

@doug-stewart
Copy link

For anyone who comes across this, the easy way to handle this is useEffect:

useEffect(() => {
    document.body.classList.add('.my-class');
    return  () => document.body.classList.remove('.my-class');
}, []):

This will add the class when a given component mounts and remove it when it dismounts. You can use a similar pattern for any other DOM manipulation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants