Created
August 18, 2024 10:10
-
-
Save prutya/569597dde9443e3d536a41ca8190041f to your computer and use it in GitHub Desktop.
A React Hook to check if JavaScript is enabled on the page. Useful for SSR scenarios (e.g. in Next.js) to progressively add functionality to you website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
export default function useIsJsEnabled() { | |
const [isJsEnabled, setIsJsEnabled] = useState(false); | |
useEffect(() => { | |
setIsJsEnabled(true); | |
}, []); | |
return isJsEnabled; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment