UNPKG

@toolpad/core

Version:

Dashboard framework powered by Material UI.

14 lines (12 loc) 686 B
'use client'; import { useStorageState, useStorageStateServer } from "../persistence/index.js"; /** * Sync state to session storage so that it persists through a page refresh. Usage is * similar to useState except we pass in a storage key so that we can default * to that value on page load instead of the specified initial value. * * Since the storage API isn't available in server-rendering environments, we * return null during SSR and hydration. */ const useSessionStorageStateBrowser = (...args) => useStorageState(window.sessionStorage, ...args); export const useSessionStorageState = typeof window === 'undefined' ? useStorageStateServer : useSessionStorageStateBrowser;