Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

recoil-nexus

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recoil-nexus - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

2

package.json
{
"name": "recoil-nexus",
"version": "0.5.0",
"version": "0.5.1",
"description": "A small Typescript package to access your Recoil atoms outside of React components.",

@@ -5,0 +5,0 @@ "main": "build/RecoilNexus.js",

@@ -51,36 +51,25 @@ # R E C O I L - N E X U S

| `getRecoilPromise` | getter function, returns a promise. To be used with asynchronous selectors. |
| `setRecoil` | setter function, pass value to be set as second parameter |
| `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:
```tsx
// Loading example
import { loadingState } from "../atoms/loadingState";
import { getRecoil, setRecoil } from "recoil-nexus";
export default function toggleLoading() {
const loading = getRecoil(loadingState);
setRecoil(loadingState, !loading);
}
const loading = getRecoil(loadingState);
```
Setting the new state like this is not inherently wrong:
```tsx
//Loader
import React from "react";
import { useRecoilValue } from "recoil";
setRecoil(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](https://github.com/luisanton-io/recoil-nexus/issues/33).
```tsx
import { setRecoil } from "recoil-nexus"
export default function Loader() {
loading = useRecoilValue(loadingState);
return loading ? <h3>Loading...</h3> : null;
export function toggleLoader() {
setRecoil(loadingState, loading => !loading)
}
```
```tsx
//Atom
import { atom } from "recoil";
export const loadingState = atom({
key: "LOADING",
default: false,
});
```
## Test Setup

@@ -87,0 +76,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc