Installations
npm install recoil-nexus
Developer
luisanton-io
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
20.10.0
NPM Version
10.2.3
Statistics
163 Stars
70 Commits
13 Forks
7 Watching
1 Branches
6 Contributors
Updated on 27 Aug 2024
Bundle Size
1.05 kB
Minified
471.00 B
Minified + Gzipped
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
2,265,969
Last day
-28.9%
2,748
Compared to previous day
Last week
-16.8%
19,359
Compared to previous week
Last month
-29.8%
91,338
Compared to previous month
Last year
87.8%
1,338,535
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
5
R E C O I L - N E X U S
If you have been using recoil for a while, you might have faced that outside React Components it's not possible to get or update values from atoms.
This Typescript implementation will workaround the issue and let you do so.
Live Example
Install
npm
npm i recoil-nexus
yarn
yarn add recoil-nexus
Usage
1. Add RecoilNexus
in your RecoilRoot
1import React from "react"; 2import { RecoilRoot } from "recoil"; 3import RecoilNexus from "recoil-nexus"; 4 5export default function App() { 6 return ( 7 <RecoilRoot> 8 <RecoilNexus /> 9 10 {/* ... */} 11 </RecoilRoot> 12 ); 13} 14 15export default App;
2. Use the following methods to get/set values passing your atom as a parameter.
Method | Returns |
---|---|
getRecoil | getter function |
getRecoilPromise | getter function, returns a promise. To be used with asynchronous selectors. |
setRecoil | setter function, pass value to be set or updater function as second parameter |
resetRecoil | pass atom as parameter to reset to default value |
Read current state:
1const loading = getRecoil(loadingState);
Setting the new state like this is not inherently wrong:
1setRecoil(loadingState, !loading);
However, if the new state depends on the previous one (like in this case), preferably use an updater function to correctly batch React state updates, as reading and updating the state at the same time could lead to unexpected results.
1import { setRecoil } from "recoil-nexus" 2 3export function toggleLoader() { 4 setRecoil(loadingState, loading => !loading) 5}
Test Setup
Jest
When testing in Jest, we need to set "transformIgnorePatterns": []
in our jest config, otherwise a SyntaxError: Cannot use import statement outside a module
will cause the tests to fail. This can be acheived one of the following ways, depending on how you are defining your jest config:
export default config
- in
jest.config.js
"transformIgnorePatterns": []
- in the top level of the
package.json
"jest": {
"transformIgnorePatterns": []
},
Credits
Kudos to VeepCream's recoil-outside original idea and Javascript implementation.
In this Typescript port/enhancement, I decided to remove RxJS and rely on native Recoil promises and loadables only.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
Found 3/25 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-11-18
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