For the complete documentation index, see llms.txt. This page is also available as Markdown.

Local Storage Value

Simple observable value that can be subscribed to, in React, using Hooks. State is automatically synced to the localStorage.

Source code is hosted on GitHub

yarn add @corets/local-storage-value

Seamless React integration is shipped in a separate package:

useValue

This is a localStorage version of this package:

Value

Quick Start

Example of how to use this package in React:

import React from "react"
import { createLocalStorageValue } from "@corets/local-storage-value"
import { useValue } from "@corets/use-value"

const Example = () => {
  const counter = useValue(() => createLocalStorageValue("storageKey", 1))
  const increment = () => counter.set(counter.get() + 1)
  
  return (
    <div>
      <button onClick={increment}>{counter.get()}</button>
    </div>
  )
}

createLocalStorageValue()

Create a new observable value:

Last updated

Was this helpful?