I'm trying to set a class conditionally on the body tag. In itself this is trivial and not an issue, but when having multiple components, that conditionally have write to the class attribute of the body tag at the same time, they start overriding each other. Only one of them stays active, while the others just get ignored. Example:
// Sidebar.js
const Sidebar = () => (
// ...
<Helmet>
<body className={menuOpen ? 'blur' : ''} />
</Helmet>
// ...
);
// Loader.js
const Loader = () => (
// ...
<Helmet>
<body className={isLoading ? 'hidden' : ''} />
</Helmet>
// ...
);
In this example, the sidebar has to disable scrolling (and blur the page, for design purposes) by setting a class on the body tag, when active. The loader needs to disable scrolling while it is active (it is a full-screen preloader). The sidebar component takes the priority here and the Helmet tag in the Loader component is just ignored.
How can I make this work?
Edit: Of course, I could just use the DOM API and set/remove classes manually, which is what I'm doing at the moment, but wondering if there is a more react-way to do this.