Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
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 8,769,192 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.