UNPKG

sanity-plugin-bulk-actions-table

Version:

A powerful table view plugin for Sanity Studio v3/v4 with bulk actions, column selection, and document management capabilities

22 lines (18 loc) 556 B
import { useEffect, useState } from 'react'; export function useStickyStateSet( defaultValue: Set<string>, key: string, ): [Set<string>, (value: Set<string>) => void] { const [value, setValue] = useState(() => { const stickyValue = window.localStorage.getItem(key); return stickyValue !== null ? new Set<string>(JSON.parse(stickyValue)) : defaultValue; }); useEffect(() => { if (value) { window.localStorage.setItem(key, JSON.stringify(Array.from(value))); } }, [key, value]); return [value, setValue]; }