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-force-update
Advanced tools
useForceUpdate
is a React Hook that forces your function component to
re-render.
useForceUpdate
does not serve a purpose in and of itself. It is a tiny
package that aims to be integrated into larger hooks, making obsolete any class
functionality that is still reliant on this.forceUpdate()
.
npm install use-force-update
oryarn add use-force-update
In its simplest form, useForceUpdate
re-renders a component.
import useForceUpdate from 'use-force-update';
let renderCount = 0;
export default function MyButton() {
const forceUpdate = useForceUpdate();
renderCount++;
return (
<>
<p>I have rendered {renderCount} times.</p>
<button onClick={forceUpdate}>
Re-render
</button>
</>
);
};
In its ideal form, useForceUpdate
integrates with event emitters, such as
state managers.
import { useEffect } from 'react';
import useForceUpdate from 'use-force-update';
import store from './store';
export default function MyButton() {
const forceUpdate = useForceUpdate();
const username = store.get('username');
useEffect(() => {
// When the username changes, re-render this component.
const selector = state => state.username;
const unsubscribe = store.subscribe(selector, forceUpdate);
// When we unmount, stop re-rendering this component.
return () => {
unsubscribe();
};
}, [forceUpdate]);
if (username === null) {
return <p>You are not logged in.</p>;
}
return <p>Hello, {username}!</p>;
};
FAQs
React Hook to force your function component to update.
We found that use-force-update 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
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.