{"repo":"dai-shi/use-context-selector","free":true,"listed":false,"github":"https://github.com/dai-shi/use-context-selector","clone":"git clone https://github.com/dai-shi/use-context-selector.git","description":"React useContextSelector hook in userland","language":"TypeScript","stars":2961,"topics":["react","react-hooks","react-context","custom-hook"],"license":"MIT","category":"ui-components","readme_excerpt":"use-context-selector React useContextSelector hook in userland [!IMPORTANT] The goal of this library is to emulate the behavior of the React Context API with Concurrent React. Many users try to use this library to avoid re-renders without needing to consider Concurrent React. If you simply want to avoid re-renders, we recommend one of the following: - Zustand - A naive implementation with useSyncExternalStore - Experimental react18-use Learn more Introduction React Context and useContext is often used to avoid prop drilling, however it's known that there's a performance issue. When a context value is changed, all components that useContext will re-render. To solve this issue, useContextSelector is proposed and later proposed Speculative Mode with context selector support. This library provides the API in userland. Prior to v1.3, it uses changedBits=0 feature to stop propagation, v1.3 no longer depends on this undocumented feature. Install This package requires some peer dependencies, which you need to install by yourself. Notes for library authors: Please do not forget to keep \"peerDependencies\" and note instructions to let users to install peer dependencies. Technical memo To make it work like original React context, it uses useReducer cheat mode intentionally. It also requires useContextUpdate to behave better in concurrent rendering. Its usage is optional and only required if the default behavior is unexpected. Usage API createContext This creates a special context for use","default_branch":null,"files":null,"tree":[],"storefront":"/r/dai-shi","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/dai-shi/use-context-selector/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}