another step just a little remaining
This commit is contained in:
@@ -15,6 +15,9 @@ export function useIsAuthenticated() {
|
||||
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// SSR-safe: read the browser-only cookie once after mount so the server-rendered
|
||||
// `false` reconciles on the client without a hydration mismatch. Deliberate setState.
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setIsAuthenticated(Boolean(getClientCookie(COOKIE_NAMES.ACCESS_TOKEN)));
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -39,7 +39,10 @@ function useIsMobileForNextJs() {
|
||||
const [onMobileDelayed, setOnMobileDelayed] = useState(SERVER_SIDE_MOBILE_FIRST);
|
||||
|
||||
useEffect(() => {
|
||||
setOnMobileDelayed(onMobile); // Next.js don't allow to use useOnMobileXxx() directly, so we need to use this workaround
|
||||
// Defer the media-query result to after mount so SSR renders the mobile-first value
|
||||
// and the client reconciles without a hydration mismatch. Deliberate setState.
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setOnMobileDelayed(onMobile);
|
||||
}, [onMobile]);
|
||||
|
||||
return onMobileDelayed;
|
||||
|
||||
Reference in New Issue
Block a user