I have a login component which when mounted the body must be like below.
<body class="login-page">
I am setting the class name using the useEffect hook like below:
useEffect(
() => {
document.body.className = "login-page";
},
[],
() => {
document.body.className = "";
}
);
After a user is successfully logged in they are redirected to the dashboard component. The body class set above must be removed before the dashboard component is mounted. The useEffect above is doing that but a user must refresh the page first to see the correct layout of the dashboard component.
How best can I remove the body class after a user is logged in so that the dashboard component's layout is not affected?