
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
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-generate 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`.
The npm package react-callback-wrapper receives a total of 1 weekly downloads. As such, react-callback-wrapper popularity was classified as not popular.
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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.