Skip to content

Instantly share code, notes, and snippets.

@JoueBien
Created January 26, 2023 07:22
Show Gist options
  • Save JoueBien/3448895ca6435323486be84254ad4801 to your computer and use it in GitHub Desktop.
Save JoueBien/3448895ca6435323486be84254ad4801 to your computer and use it in GitHub Desktop.
useIsSSR
// Libs
import { useEffect, useState } from "react";
export default function useIsSSR() {
// Local State
const [isClient, setIsClient] = useState<boolean>(false);
const [isSSR, setIsSSR] = useState<boolean>(true);
// On Mount set where we are
useEffect(() => {
setIsClient(true);
setIsSSR(false);
}, []);
return {
isClient,
isSSR,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment