Skip to content

Instantly share code, notes, and snippets.

@prutya
Created August 18, 2024 10:10
Show Gist options
  • Save prutya/569597dde9443e3d536a41ca8190041f to your computer and use it in GitHub Desktop.
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
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