useForceUpdate: Return stable function (#86094)

This commit is contained in:
Torkel Ödegaard 2024-04-15 09:13:16 +02:00 committed by GitHub
parent 23cd2d3e6f
commit 31879f1f5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
import { useState } from 'react';
import { useCallback, useState } from 'react';
/** @internal */
export function useForceUpdate() {
const [_, setValue] = useState(0); // integer state
return () => setValue((prevState) => prevState + 1); // update the state to force render
return useCallback(() => setValue((prevState) => prevState + 1), []);
}