Registry / storage / create-ls

create-ls

JSON →
library1.2.2jsnpmunverified

A lightweight React state manager for local storage with real-time cross-tab sync. current version 1.2.2, released periodically. Key differentiators: no external dependencies, simple hook-based API (get/set/reset/hasValue), automatic persistence and synchronization across tabs. Eliminates need for Redux, Context API, or Zustand for persistent state. ESM-only, requires React 19.

npm install create-ls
INSTALL
IMPORT
SIG · CREATE-LS
C
create-ls
storagejavascriptv1.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createLS
✓ import { createLS } from 'create-ls'
✗ const createLS = require('create-ls')
ESM-only package. CommonJS require will fail.
createLS
✓ import { createLS } from 'create-ls'
✗ import createLS from 'create-ls'
createLS is a named export, not default.
get
✓ const counter = createLS('key'); counter.get()
✗ const { get } = createLS('key')
createLS returns an object with methods; destructuring is fine but get is a method, not standalone.
set
✓ const counter = createLS('key'); counter.set(value)
✗ const { set } = createLS('key'); set(value)
Destructuring set is allowed but misleading; set must be called on the returned object.

Shows basic usage of createLS hook: initializing, getting, setting, resetting a persistent counter.

"use client"; import { createLS } from 'create-ls'; const Page: React.FC = () => { const counter = createLS('count', 0); return ( <div> {counter.hasValue() ? ( <h1>Count: {counter.get()}</h1> ) : ( <h1>Click the button to set the count</h1> )} <button onClick={() => counter.set(counter.get() + 1)}> Increment by 1 </button> <button onClick={() => counter.reset()}> Reset </button> </div> ); }; export default Page;
Debug
Known issues
gotchacreateLS must be called inside a React component or custom hook (client-side only).
fix
Ensure the component is a client component ("use client") and avoid calling createLS in non-React contexts.
affects: >=1.0.0
gotchacreateLS does not support server-side rendering; it will throw if called on the server.
fix
Use dynamic import or conditional rendering to avoid SSR issues, or wrap with 'use client'.
affects: >=1.0.0
deprecatedIn v1.2.0, the 'hasValue' property changed from a function to a boolean (breaking change).
fix
Update to v1.2.0+ and use hasValue as a boolean property (no parentheses) if you were calling it as hasValue().
affects: <1.2.0
breakingIn v1.0.0, the package switched from CommonJS to ESM. require() will no longer work.
fix
Use ESM import syntax (import { createLS } from 'create-ls') or upgrade to a bundler that supports ESM.
affects: >=1.0.0
gotchacreateLS only works with string keys; using non-string keys will cause an error.
fix
Always pass a string as the first argument to createLS.
affects: >=1.0.0
Errors
Common errors & fixes
Error: createLS is not a function
Default import instead of named import.
fix
Change import createLS from 'create-ls' to import { createLS } from 'create-ls'
TypeError: Cannot read properties of undefined (reading 'get')
Calling createLS outside of a React component or before it's initialized.
fix
Ensure createLS is called within a React component (client-side) and after the component mounts.
Module not found: Error: Can't resolve 'create-ls'
Package not installed or wrong import path.
fix
Run `npm install create-ls` and verify the import path is correct: 'create-ls'
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
reactrequiredPeer dependency; required for hooks
Agent activity
18 hits · last 30 days
node
16
Resources
create-ls — npm install create-ls · libregistry