use-hashed-state
Advanced tools
Comparing version 0.3.5 to 0.4.0
@@ -1,1 +0,1 @@ | ||
import g from"node-object-hash";import{useEffect as c,useState as d}from"react";var y="__use_hashed_state_hook",p=g({trim:!0,sort:!0}),f=e=>{try{let t=window.localStorage.getItem(e);if(t)return JSON.parse(t)}catch(t){console.error("error in useHashedState: ",t)}},u=(e,t)=>{window.localStorage.setItem(e,JSON.stringify(t))},m=(e,t=y)=>{let s=p.hash(e);return[`${t}_initial_${s}`,`${t}_value_${s}`]},H=(e,t,s=y)=>{let[h,o]=m(e,s),[S,_]=d(!1),[r,n]=d(typeof window!="undefined"&&f(o)||(t instanceof Function?t():t)),a=t===void 0?void 0:p.hash(t);return c(()=>n(t),[t,a]),c(()=>{u(h,a)},[h,a]),c(()=>{S?u(o,r):(n(()=>f(o)||(t instanceof Function?t():t)),_(!0))},[e,S,t,r,o]),[r,n]};export{y as DEFAULT_PREFIX,m as getHashKeyPairs,p as hasher,H as useHashedState}; | ||
import{hasher as g}from"node-object-hash";import{useEffect as c,useState as d}from"react";var y="__use_hashed_state_hook",p=g({trim:!0,sort:!0}),f=e=>{try{let t=window.localStorage.getItem(e);if(t)return JSON.parse(t)}catch(t){console.error("error in useHashedState: ",t)}},u=(e,t)=>{window.localStorage.setItem(e,JSON.stringify(t))},m=(e,t=y)=>{let s=p.hash(e);return[`${t}_initial_${s}`,`${t}_value_${s}`]},H=(e,t,s=y)=>{let[h,o]=m(e,s),[S,_]=d(!1),[r,n]=d(typeof window!="undefined"&&f(o)||(t instanceof Function?t():t)),a=t===void 0?void 0:p.hash(t);return c(()=>n(t),[t,a]),c(()=>{u(h,a)},[h,a]),c(()=>{S?u(o,r):(n(()=>f(o)||(t instanceof Function?t():t)),_(!0))},[e,S,t,r,o]),[r,n]};export{y as DEFAULT_PREFIX,m as getHashKeyPairs,p as hasher,H as useHashedState}; |
@@ -1,6 +0,6 @@ | ||
import createHash from 'node-object-hash'; | ||
import * as node_object_hash from 'node-object-hash'; | ||
import { Dispatch, SetStateAction } from 'react'; | ||
declare const DEFAULT_PREFIX = "__use_hashed_state_hook"; | ||
declare const hasher: createHash.Hasher; | ||
declare const hasher: node_object_hash.Hasher<unknown>; | ||
declare const getHashKeyPairs: (key: any, prefix?: string) => string[]; | ||
@@ -7,0 +7,0 @@ declare const useHashedState: <T = any>(key: any, initialValue?: T | (() => T), prefix?: string) => [T, Dispatch<SetStateAction<T>>]; |
@@ -1,1 +0,1 @@ | ||
import g from"node-object-hash";import{useEffect as c,useState as d}from"react";var y="__use_hashed_state_hook",p=g({trim:!0,sort:!0}),f=e=>{try{let t=window.localStorage.getItem(e);if(t)return JSON.parse(t)}catch(t){console.error("error in useHashedState: ",t)}},u=(e,t)=>{window.localStorage.setItem(e,JSON.stringify(t))},m=(e,t=y)=>{let s=p.hash(e);return[`${t}_initial_${s}`,`${t}_value_${s}`]},H=(e,t,s=y)=>{let[h,o]=m(e,s),[S,_]=d(!1),[r,n]=d(typeof window!="undefined"&&f(o)||(t instanceof Function?t():t)),a=t===void 0?void 0:p.hash(t);return c(()=>n(t),[t,a]),c(()=>{u(h,a)},[h,a]),c(()=>{S?u(o,r):(n(()=>f(o)||(t instanceof Function?t():t)),_(!0))},[e,S,t,r,o]),[r,n]};export{y as DEFAULT_PREFIX,m as getHashKeyPairs,p as hasher,H as useHashedState}; | ||
import{hasher as g}from"node-object-hash";import{useEffect as c,useState as d}from"react";var y="__use_hashed_state_hook",p=g({trim:!0,sort:!0}),f=e=>{try{let t=window.localStorage.getItem(e);if(t)return JSON.parse(t)}catch(t){console.error("error in useHashedState: ",t)}},u=(e,t)=>{window.localStorage.setItem(e,JSON.stringify(t))},m=(e,t=y)=>{let s=p.hash(e);return[`${t}_initial_${s}`,`${t}_value_${s}`]},H=(e,t,s=y)=>{let[h,o]=m(e,s),[S,_]=d(!1),[r,n]=d(typeof window!="undefined"&&f(o)||(t instanceof Function?t():t)),a=t===void 0?void 0:p.hash(t);return c(()=>n(t),[t,a]),c(()=>{u(h,a)},[h,a]),c(()=>{S?u(o,r):(n(()=>f(o)||(t instanceof Function?t():t)),_(!0))},[e,S,t,r,o]),[r,n]};export{y as DEFAULT_PREFIX,m as getHashKeyPairs,p as hasher,H as useHashedState}; |
{ | ||
"name": "use-hashed-state", | ||
"version": "0.3.5", | ||
"version": "0.4.0", | ||
"description": "Safely store data in localstorage with an unique key of any type, even a component", | ||
@@ -29,3 +29,3 @@ "type": "module", | ||
"dependencies": { | ||
"node-object-hash": "2.3.10" | ||
"node-object-hash": "3.0.0" | ||
}, | ||
@@ -36,4 +36,4 @@ "devDependencies": { | ||
"@testing-library/react": "14.0.0", | ||
"@types/node": "18.15.11", | ||
"@types/react": "18.0.33", | ||
"@types/node": "18.15.12", | ||
"@types/react": "18.0.37", | ||
"cross-env": "7.0.3", | ||
@@ -40,0 +40,0 @@ "jest": "29.5.0", |
Unpublished package
Supply chain riskPackage version was not found on the registry. It may exist on a different registry and need to be configured to pull from that registry.
Found 1 instance in 1 package
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
6072
0
1
+ Addednode-object-hash@3.0.0(transitive)
- Removednode-object-hash@2.3.10(transitive)
Updatednode-object-hash@3.0.0