Local Storage

Simple helpers for managing local storage in your React applications.

import { getLocalStorage, setLocalStorage } from '@cerberus/react'

Usage

page.tsx
'use client';
import { getLocalStorage } from '@cerberus/react'
import { useState } from 'react'
export default function Page() {
const [value, setValue] = useState<string>('')
// You have to wait until the component is mounted to
// have access to the local storage
useEffect(() => {
const value = getLocalStorage('key')
setValue(value)
}, [])
return (
<Text>
This is from local storage: {value}
</Text>
)
}

API

getLocalStorage

NameDefaultDescription
keyThe key that the value is saved under
defaultValueThe default value to return if the key does not exist in localStorage

setLocalStorage

NameDefaultDescription
keyThe key to save the value under
valueThe value to save in localStorage

On this page