mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-06 07:37:56 +02:00
CODEBASE: Add custom useRerender hook (#359)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
/** Hook that returns a function for the component. Optionally set an interval to rerender the component.
|
||||
* @param autoRerenderTime: Optional. If provided and nonzero, used as the ms interval to automatically call the rerender function.
|
||||
*/
|
||||
export function useRerender(autoRerenderTime?: number) {
|
||||
const setRerender = useState(false)[1];
|
||||
const rerender = () => setRerender((old) => !old);
|
||||
useEffect(() => {
|
||||
if (!autoRerenderTime) return;
|
||||
const intervalID = setInterval(rerender, autoRerenderTime);
|
||||
return () => clearInterval(intervalID);
|
||||
}, []);
|
||||
return rerender;
|
||||
}
|
||||
Reference in New Issue
Block a user