
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-callback-wrapper
Advanced tools
Allows to optimize components re-rendering using `memo`, substitutes `useCallback`.
Allows to optimize components re-rendering using memo, substitutes useCallback.
With useCallback we have a problem that when state is changed, callback function is re-generated as well (we should specify state as dependents) and, as result, all components which depend on this callback, are re-rendered.
Using callback-wrapper it is possible to keep callback function immutable and still have a fresh state inside.
Just install the package:
npm i --save react-callback-wrapper
And wrap your callback with cbw:
import React, { memo, useState } from 'react'
import ReactDOM from 'react-dom'
import cbw from 'react-callback-wrapper'
const Button = memo(({ onClick, children }) => {
console.log('render')
return (
<button onClick={onClick}>{children}</button>
)
})
function App() {
const [count, setCount] = useState(0)
const inc = cbw(() => {
setCount(count + 1)
})
useEffect(() => {
const timer = setInterval(inc, 1000)
return () => clearInterval(timer)
}, [])
return (
<>
{count}
<Button onClick={cbw(() => setCount(count + 1))}>inc</Button>
<Button onClick={cbw(() => setCount(count - 1))}>dec</Button>
</>
)
}
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
)
FAQs
Allows to optimize components re-rendering using `memo`, substitutes `useCallback`.
We found that react-callback-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.