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
26 lines (21 loc) • 610 B
text/typescript
import { useEffect, useState } from 'react';
export interface ColumnOrder {
key: string;
direction: string;
type: string | null;
}
export function useStickyStateOrder(
defaultValue: ColumnOrder,
key: string,
): [ColumnOrder, (value: ColumnOrder) => void] {
const [value, setValue] = useState(() => {
const stickyValue = window.localStorage.getItem(key);
return stickyValue !== null ? JSON.parse(stickyValue) : defaultValue;
});
useEffect(() => {
if (value) {
window.localStorage.setItem(key, JSON.stringify(value));
}
}, [key, value]);
return [value, setValue];
}