Installations
npm install recoil-custom-persist
Developer Guide
Typescript
Yes
Module System
CommonJS
Score
60.8
Supply Chain
98.3
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (81.55%)
JavaScript (16.62%)
HTML (1.82%)
Developer
thanhlmm
Download Statistics
Total Downloads
997
Last Day
4
Last Week
8
Last Month
20
Last Year
148
GitHub Statistics
1 Stars
91 Commits
2 Watching
2 Branches
1 Contributors
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
997
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
27
Recoil Custom Persist
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)
Install
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
.
Usage
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})
API
recoilPersist(config)
config parameter
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).
Migration from version 1.x.x to 2.x.x
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);
Demo
$ 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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
49 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-8mmm-9v2q-x3f9
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5
- Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp
- Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq
- Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr
- Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765
- Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
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