How to use the ahooks.useLocalStorageState function in ahooks

To help you get started, we’ve selected a few ahooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pingcap / tidb-dashboard / ui / lib / utils / useOrderState.ts View on Github external
export default function useOrderState(
  storeKeyPrefix: string,
  needSave: boolean,
  options: IOrderOptions
) {
  const storeKey = `${storeKeyPrefix}.order_options`
  const [memoryOrderOptions, setMemoryOrderOptions] = useState(options)
  const [localOrderOptions, setLocalOrderOptions] = useLocalStorageState(
    storeKey,
    options
  )
  const orderOptions = useMemo(
    () => (needSave ? localOrderOptions : memoryOrderOptions),
    [needSave, memoryOrderOptions, localOrderOptions]
  )

  function changeOrder(orderBy: string, desc: boolean) {
    if (needSave) {
      setLocalOrderOptions({
        orderBy,
        desc,
      })
    } else {
      setMemoryOrderOptions({