Class

useLocalStorage

useLocalStorage(key, initialValue) → {UseLocalStorageResult.<T>}

The hook which allows you to store particular data into local storage.

It works very similar to useState with the exception that it requires the key under which data will be stored.

Usage

import { useLocalStorage } from 'admin-bro'

const MyRecordActionComponent = (props) => {
  const [isOpen, setIsOpen] = useLocalStorage('isSidebarOpen', false)
  // ....

  return (
    <Box>
      { isOpen ? (
        <Drawer>
          Drawer content
        </Drawer>
      ) : ''}
    </Box>
  )
}
export default MyRecordActionComponent

Returns UseRecordResult.

Constructor

# new useLocalStorage(key, initialValue) → {UseLocalStorageResult.<T>}

The hook which allows you to store particular data into local storage.

It works very similar to useState with the exception that it requires the key under which data will be stored.

Usage

import { useLocalStorage } from 'admin-bro'

const MyRecordActionComponent = (props) => {
  const [isOpen, setIsOpen] = useLocalStorage('isSidebarOpen', false)
  // ....

  return (
    <Box>
      { isOpen ? (
        <Drawer>
          Drawer content
        </Drawer>
      ) : ''}
    </Box>
  )
}
export default MyRecordActionComponent

Returns UseRecordResult.

Parameters:
Name Type Description
key string

key under which hook will store the data

initialValue T

value which will be stringified and stored

New:
  • In version 3.3
See:

View Source admin-bro/src/frontend/hooks/use-local-storage/use-local-storage.ts, line 17

Type Definitions

Array

# UseLocalStorageResult

Result of the useLocalStorage. It is a tuple containing value and the setter

Properties:
Name Type Attributes Description
0 T <optional>

the value stored in the local store

1 React.Dispatch.<React.SetStateAction.<T>> <optional>

value setter compatible with react useState

View Source admin-bro/src/frontend/hooks/use-local-storage/use-local-storage-result.type.ts, line 2

SoftwareBrothers

Proudly built and maintained by SoftwareBrothers

Software House with a passion for both JavaScript and TypeScript.

See what we do See what we believe in

Proudly built and maintained by

SoftwareBrothers