use-hashed-state
Advanced tools
Comparing version 0.2.4 to 0.3.0
@@ -1,1 +0,1 @@ | ||
import m from"node-object-hash";import{useEffect as c,useState as d}from"react";var y="__use_hashed_state_hook",_=m({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))},p=(e,t=y)=>{let s=_.hash(e);return[`${t}_initial_${s}`,`${t}_value_${s}`]},F=(e,t,s=y)=>{let[h,o]=p(e,s),[S,g]=d(!1),[r,n]=d(typeof window<"u"&&f(o)||(t instanceof Function?t():t)),a=t===void 0?void 0:_.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)),g(!0))},[e,S,t,r,o]),[r,n]};export{y as DEFAULT_PREFIX,p as getHashKeyPairs,_ as hasher,F as useHashedState}; | ||
import m from"node-object-hash";import{useEffect as c,useState as d}from"react";var y="__use_hashed_state_hook",_=m({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))},p=(e,t=y)=>{let s=_.hash(e);return[`${t}_initial_${s}`,`${t}_value_${s}`]},F=(e,t,s=y)=>{let[h,o]=p(e,s),[S,g]=d(!1),[r,n]=d(typeof window!="undefined"&&f(o)||(t instanceof Function?t():t)),a=t===void 0?void 0:_.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)),g(!0))},[e,S,t,r,o]),[r,n]};export{y as DEFAULT_PREFIX,p as getHashKeyPairs,_ as hasher,F as useHashedState}; |
{ | ||
"name": "use-hashed-state", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"description": "Safely store data in localstorage with an unique key of any type, even a component", | ||
@@ -32,12 +32,12 @@ "type": "module", | ||
"devDependencies": { | ||
"@jest/globals": "29.1.2", | ||
"@jest/types": "29.1.2", | ||
"@plasmohq/prettier-plugin-sort-imports": "3.5.4", | ||
"@plasmohq/storage": "0.12.2", | ||
"@jest/globals": "29.3.1", | ||
"@jest/types": "29.3.1", | ||
"@plasmohq/prettier-plugin-sort-imports": "3.6.0", | ||
"@plasmohq/storage": "0.13.0", | ||
"@testing-library/react": "13.4.0", | ||
"@types/node": "18.8.3", | ||
"@types/react": "18.0.21", | ||
"@types/node": "18.11.9", | ||
"@types/react": "18.0.25", | ||
"cross-env": "7.0.3", | ||
"jest": "29.1.2", | ||
"jest-environment-jsdom": "29.1.2", | ||
"jest": "29.3.1", | ||
"jest-environment-jsdom": "29.3.1", | ||
"prettier": "2.7.1", | ||
@@ -48,4 +48,4 @@ "react": "18.2.0", | ||
"ts-jest": "29.0.3", | ||
"tsup": "6.2.3", | ||
"typescript": "4.8.4" | ||
"tsup": "6.5.0", | ||
"typescript": "4.9.3" | ||
}, | ||
@@ -52,0 +52,0 @@ "scripts": { |
@@ -54,2 +54,2 @@ # use-hashed-state | ||
[MIT](./license) 🖖 [Plasmo Corp.](https://plasmo.com) | ||
[MIT](./LICENSE) 🖖 [Plasmo Corp.](https://plasmo.com) |
5344