You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

use-hashed-state

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-hashed-state

Safely store data in localstorage with an unique key of any type, even a component

0.1.3
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

use-hashed-state

use-hashed-state is a hook library from plasmo to safely store data in localstorage with an unique key of any type, even a component.

The library is a typescript fork of use-persisted-state-hook but instead of md5, is uses node-object-hash, and it hashes both the key and the values.

Example

The Check component below is capable of having a state simply based on the content of its children - it is fully independent.

import { useHashedState } from "use-hashed-state"

const Check = ({ children = "" as ReactNode }) => {
  const [checked, setChecked] = useHashedState<boolean>(
    children,
    false,
    "plasmo-soc2"
  )
  return (
    <Checkbox checked={checked} onChange={() => setChecked((c) => !c)}>
      {children}
    </Checkbox>
  )
}

// Consume in another component:
const Container = () => (
  <>
    <Check>
      <WaveIcon /> Waved
    </Check>
    <Check>
      <ClockTick />
    </Check>
  </>
)

Usage in the wild

Why?

To boldly go where no one has gone before

Acknowledgment

License

MIT 🖖 Plasmo Corp.

Keywords

localstorage

FAQs

Package last updated on 17 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts