完成流水线控制器重构和相关功能改进
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import type React from 'react';
|
||||
import { useEffect, useCallback } from 'react';
|
||||
|
||||
export function useAsyncEffect(
|
||||
effect: () => Promise<void>,
|
||||
effect: () => Promise<void | (() => void)>,
|
||||
deps: React.DependencyList,
|
||||
) {
|
||||
const callback = useCallback(effect, [...deps]);
|
||||
|
||||
useEffect(() => {
|
||||
effect();
|
||||
}, [...deps]);
|
||||
const cleanupPromise = callback();
|
||||
return () => {
|
||||
if (cleanupPromise instanceof Promise) {
|
||||
cleanupPromise.then(cleanup => cleanup && cleanup());
|
||||
}
|
||||
};
|
||||
}, [callback]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user