I have read #7322 #7423, which is similar to my questions.
However, I don't use any Styled components and these solutions above can not help me.
The className of 'token' should be bind on the DOM correctly.


This makes a lot of sense, as you are using a browser functionality and you are expecting it to work on the server as well.
export default () => {
const token = process.browser ? localStorage.getItem('token') : ''
const className = token ? 'token' : ''
console.log('className:', className);
return (
<div className={className}>
{token}
</div>
)
}
To fix your problem, I would wrap that code in an useEffect call and update it when mounted.
This is not a nextjs specific problem, but how react SSR hydration works.
For further issues, please ask here https://spectrum.chat/zeit.
Close this bug request.
This makes a lot of sense, as you are using a browser functionality and you are expecting it to work on the server as well.
export default () => { const token = process.browser ? localStorage.getItem('token') : '' const className = token ? 'token' : '' console.log('className:', className); return ( <div className={className}> {token} </div> ) }To fix your problem, I would wrap that code in an
useEffectcall and update it when mounted.This is not a nextjs specific problem, but how react SSR hydration works.
For further issues, please ask here https://spectrum.chat/zeit.Close this bug request.
Thanks, It is fixed by using useEffect.
Most helpful comment
This makes a lot of sense, as you are using a browser functionality and you are expecting it to work on the server as well.
To fix your problem, I would wrap that code in an
useEffectcall and update it when mounted.This is not a nextjs specific problem, but how react SSR hydration works.
For further issues, please ask here https://spectrum.chat/zeit.
Close this bug request.