useLocalStorage
Store, retrieve, and synchronize data from the browser’s localStorage API with useLocalStorage
Installation
Copy and paste the following code into your project.
Usage
API
Parameters
Name | Type | Description |
---|---|---|
key | string | The key to store the value under. It should be unique to avoid collisions with other libraries or components. |
initialValue | any | The default value to use if nothing is stored in localStorage. |
Return value
Name | Type | Description |
---|---|---|
value | any | The value stored in local storage. If nothing is stored, the initial value is returned. |
setValue | (value: any) => void | A function to set the value in local storage. This function will also persist the value to local storage. |