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

@nanostores/react

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nanostores/react - npm Package Compare versions

Comparing version 0.7.3 to 0.8.0

9

index.d.ts
import type { Store, StoreValue } from 'nanostores'
import type { DependencyList } from 'react'

@@ -9,2 +10,10 @@ type StoreKeys<T> = T extends { setKey: (k: infer K, v: any) => unknown }

/**
* @default
* ```ts
* [store, options.keys]
* ```
*/
deps?: DependencyList
/**
* Will re-render components only on specific key changes.

@@ -11,0 +20,0 @@ */

23

index.js
import { listenKeys } from 'nanostores'
import { useCallback, useSyncExternalStore } from 'react'
import { useCallback, useRef, useSyncExternalStore } from 'react'
export function useStore(store, opts = {}) {
let emit = (snapshotRef, onChange) => value => {
snapshotRef.current = value
onChange()
}
export function useStore(store, { keys, deps = [store, keys] } = {}) {
let snapshotRef = useRef()
snapshotRef.current = store.get()
let subscribe = useCallback(
onChange =>
opts.keys
? listenKeys(store, opts.keys, onChange)
: store.listen(onChange),
[opts.keys, store]
keys?.length > 0
? listenKeys(store, keys, emit(snapshotRef, onChange))
: store.listen(emit(snapshotRef, onChange)),
deps
)
let get = () => snapshotRef.current
let get = store.get.bind(store)
return useSyncExternalStore(subscribe, get, get)
}
{
"name": "@nanostores/react",
"version": "0.7.3",
"version": "0.8.0",
"description": "React integration for Nano Stores, a tiny state manager with many atomic tree-shakable stores",

@@ -5,0 +5,0 @@ "keywords": [

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