Gathering detailed insights and metrics for recoil-custom-persist
Gathering detailed insights and metrics for recoil-custom-persist
npm install recoil-custom-persist
Typescript
Module System
60.8
Supply Chain
98.3
Quality
75.2
Maintenance
100
Vulnerability
100
License
TypeScript (81.55%)
JavaScript (16.62%)
HTML (1.82%)
Total Downloads
997
Last Day
4
Last Week
8
Last Month
20
Last Year
148
1 Stars
91 Commits
2 Watching
2 Branches
1 Contributors
Latest Version
2.6.2
Package Id
recoil-custom-persist@2.6.2
Unpacked Size
16.05 kB
Size
5.13 kB
File Count
11
Cumulative downloads
Total Downloads
Last day
0%
4
Compared to previous day
Last week
14.3%
8
Compared to previous week
Last month
150%
20
Compared to previous month
Last year
-8.6%
148
Compared to previous year
1
27
Tiny module for recoil to store and sync state to
Storage
. It is only 354 bytes (minified and gzipped). No dependencies.
Size Limit controls the size.
If you are using recoil-persist with version 1.x.x please check migration guide to version 2.x.x.
1import React from 'react' 2import ReactDOM from 'react-dom' 3import App from './App' 4import { atom, RecoilRoot, useRecoilState } from 'recoil' 5import { recoilPersist } from 'recoil-custom-persist' 6 7const { persistAtom } = recoilPersist()() 8 9const counterState = atom({ 10 key: 'count', 11 default: 0, 12 effects_UNSTABLE: [persistAtom], 13}) 14 15function App() { 16 const [count, setCount] = useRecoilState(counterState) 17 return ( 18 <div> 19 <h3>Counter: {count}</h3> 20 <button onClick={() => setCount(count + 1)}>Increase</button> 21 <button onClick={() => setCount(count - 1)}>Decrease</button> 22 </div> 23 ) 24} 25 26ReactDOM.render( 27 <React.StrictMode> 28 <RecoilRoot> 29 <App /> 30 </RecoilRoot> 31 </React.StrictMode>, 32 document.getElementById('root'), 33)
npm install recoil-custom-persist
or
yarn add recoil-custom-persist
Now you could add persisting a state to your app:
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import App from './App'; 4import { RecoilRoot } from "recoil"; 5+import { recoilPersist } from 'recoil-persist' 6 7+const { persistAtom } = recoilPersist()() 8 9const counterState = atom({ 10 key: 'count', 11 default: 0, 12+ effects_UNSTABLE: [persistAtom], 13}) 14 15function App() { 16 const [count, setCount] = useRecoilState(counterState) 17 return ( 18 <div> 19 <h3>Counter: {count}</h3> 20 <button onClick={() => setCount(count + 1)}>Increase</button> 21 <button onClick={() => setCount(count - 1)}>Decrease</button> 22 </div> 23 ) 24} 25 26ReactDOM.render( 27 <React.StrictMode> 28 <RecoilRoot> 29 <App /> 30 </RecoilRoot> 31 </React.StrictMode>, 32 document.getElementById('root'), 33)
After this each changes in atom will be store and sync to localStorage
.
1import { recoilPersist } from 'recoil-persist'
2
3const { persistAtom } = recoilPersist({
4 key: 'recoil-persist', // this key is using to store data in local storage
5 storage: localStorage, // configurate which stroage will be used to store the data
6})({
7 serialize: (input) => JSON.stringify(input), // Custom serialize function
8 deserialize: (input) => JSON.parse(input) // Custom deserialize function
9})
1type config.key = String
Default value of config.key
is recoil-persist
. This key is using to store
data in storage.
1type config.storage = Storage
Set config.storage
with sessionStorage
or other Storage
implementation to
change storage target. Otherwise localStorage
is used (default).
The API changed from version 1.x.x.
To update your code just use this migration guide:
1import React from 'react'; 2import ReactDOM from 'react-dom'; 3import App from './App'; 4import { RecoilRoot } from "recoil"; 5import { recoilPersist } from 'recoil-persist' // import stay the same 6 7const { 8- RecoilPersist, 9- updateState 10+ persistAtom 11} = recoilPersist( 12- ['count'], // no need for specifying atoms keys 13 { 14 key: 'recoil-persist', // configuration stay the same too 15 storage: localStorage 16 } 17) 18 19const counterState = atom({ 20 key: 'count', 21 default: 0, 22- persistence_UNSTABLE: { // Please remove persistence_UNSTABLE from atom definition 23- type: 'log', 24- }, 25+ effects_UNSTABLE: [persistAtom], // Please add effects_UNSTABLE key to atom definition 26}) 27 28function App() { 29 const [count, setCount] = useRecoilState(counterState) 30 return ( 31 <div> 32 <h3>Counter: {count}</h3> 33 <button onClick={() => setCount(count + 1)}>Increase</button> 34 <button onClick={() => setCount(count - 1)}>Decrease</button> 35 </div> 36 ) 37} 38 39ReactDOM.render( 40 <React.StrictMode> 41- <RecoilRoot initializeState={({set}) => updateState({set})> 42+ <RecoilRoot> // Please remove updateState function from initiallizeState 43- <RecoilPersist /> // and also remove RecoilPersist component 44 <App /> 45 </RecoilRoot> 46 </React.StrictMode>, 47 document.getElementById('root') 48);
$ git clone git@github.com:thanhlmm/recoil-persist.git
$ cd recoil-persist
$ npm install
$ npm run start
Please open localhost:1234.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
49 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More