
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
react-context-with-selector
Advanced tools
use React Context with selector
When the value of React Context changes, all components that use useContext are re-rendered. This causes unnecessary re-rendering.
Using this library, can solve this issue.
This package has peer dependencies, which you need to install by yourself.
// npm
npm install use-context-selector react
// yarn
yarn add use-context-selector react
import { memo, useCallback, useMemo, useState } from "react";
import { createContext } from "react-context-with-selector";
const CountContext = createContext({
count: 0,
count2: 0,
increment: () => {},
increment2: () => {},
});
const Counter = memo(() => {
const count = CountContext.useContext((state) => state.count);
const increment = CountContext.useContext((state) => state.increment);
return (
<div>
<span>Count: {count}</span>
<button type="button" onClick={increment}>
increment
</button>
</div>
);
});
const Counter2 = memo(() => {
const count = CountContext.useContext((state) => state.count2);
const increment = CountContext.useContext((state) => state.increment2);
return (
<div>
<span>Count: {count}</span>
<button type="button" onClick={increment}>
increment
</button>
</div>
);
});
const CounterContainer = () => {
const [count, setCount] = useState(0);
const [count2, setCount2] = useState(0);
const increment = useCallback(() => {
setCount((_count) => _count + 1);
}, []);
const increment2 = useCallback(() => {
setCount2((_count) => _count + 1);
}, []);
const contextValues = useMemo(
() => ({ count, increment, count2, increment2 }),
[count, count2, increment, increment2]
);
return (
<CountContext.Provider value={contextValues}>
<Counter />
<Counter2 />
</CountContext.Provider>
);
};
FAQs
use React Context with selector
The npm package react-context-with-selector receives a total of 0 weekly downloads. As such, react-context-with-selector popularity was classified as not popular.
We found that react-context-with-selector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.