UNPKG

react-storage-complete

Version:

🗄️ React hooks for accessing localStorage and sessionStorage, with syncing and prefix support. The complete package.

22 lines (21 loc) 839 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useClientReady = void 0; const react_1 = __importDefault(require("react")); /** * Returns false if SSR, or if the client (browser) has not finished rendering, * and returns true when running as a client after useEffect completes. * You can use this hook to avoid hydration issues. * See: https://blog.logrocket.com/fixing-gatsbys-rehydration-issue/ */ const useClientReady = () => { const [isClientReady, setClientReady] = react_1.default.useState(false); react_1.default.useEffect(() => { setClientReady(true); }, []); return isClientReady; }; exports.useClientReady = useClientReady;