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.
# 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 |
Type Definitions
# 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 |