feat(admin, settlement, dashboard): strengthen permission gating and billing workflows
This commit is contained in:
@@ -6,15 +6,22 @@ import { useEffect, useRef, type DependencyList } from "react";
|
||||
* 在依赖变化时执行异步副作用;factory 始终用最新闭包,但不必把 `t` 等不稳定引用放进 deps。
|
||||
*/
|
||||
export function useAsyncEffect(
|
||||
factory: () => void | Promise<void>,
|
||||
factory: () => void | (() => void) | Promise<void>,
|
||||
deps: DependencyList,
|
||||
): void {
|
||||
const factoryRef = useRef(factory);
|
||||
factoryRef.current = factory;
|
||||
|
||||
useEffect(() => {
|
||||
let cleanup: void | (() => void);
|
||||
queueMicrotask(() => {
|
||||
void factoryRef.current();
|
||||
void Promise.resolve(factoryRef.current()).then((result) => {
|
||||
cleanup = result;
|
||||
});
|
||||
});
|
||||
|
||||
return () => {
|
||||
cleanup?.();
|
||||
};
|
||||
}, deps);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user