Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
use-sync-external-store
Advanced tools
Backwards compatible shim for React's useSyncExternalStore. Works with any React that supports hooks.
The use-sync-external-store package provides a hook that allows React components to read from an external, synchronous data source and subscribe to updates from that source. It is designed to be a primitive hook for creating other hooks that need to subscribe to external data sources.
Subscribing to an external store
This feature allows you to create a custom hook that subscribes to an external store. The hook will re-render the component whenever the store updates.
import { useSyncExternalStore } from 'use-sync-external-store';
function useCustomHook(store) {
const state = useSyncExternalStore(
store.subscribe,
store.getSnapshot,
store.getServerSnapshot
);
return state;
}
React Redux provides a 'useSelector' hook that allows you to read data from a Redux store and subscribe to updates. It is similar to use-sync-external-store but is specifically tailored for Redux state management.
MobX React Lite offers 'useObserver' and other hooks to reactively work with MobX stores. It provides a way to connect React components to MobX observables, similar to how use-sync-external-store connects components to external stores.
Recoil provides a 'useRecoilValue' hook that subscribes to changes in an atom or selector, which is conceptually similar to use-sync-external-store's ability to subscribe to external data sources.
Zustand is a state management library that offers a hook-based API to subscribe to global state within React components. It is similar to use-sync-external-store in that it allows components to react to external state changes.
Backwards-compatible shim for React.useSyncExternalStore
. Works with any React that supports Hooks.
See also https://github.com/reactwg/react-18/discussions/86.
FAQs
Backwards compatible shim for React's useSyncExternalStore. Works with any React that supports hooks.
The npm package use-sync-external-store receives a total of 10,473,776 weekly downloads. As such, use-sync-external-store popularity was classified as popular.
We found that use-sync-external-store demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.