mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-28 15:55:19 +08:00
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { type DependencyList } from 'react';
|
||||
|
||||
export type AsyncErrorHandler = (error: Error) => void;
|
||||
|
||||
@@ -17,7 +17,7 @@ export const AsyncCallbackContext = React.createContext<AsyncErrorHandler>(
|
||||
*/
|
||||
export function useAsyncCallback<T extends any[]>(
|
||||
callback: (...args: T) => Promise<void>,
|
||||
deps: any[]
|
||||
deps: DependencyList
|
||||
): (...args: T) => void {
|
||||
const handleAsyncError = React.useContext(AsyncCallbackContext);
|
||||
return React.useCallback(
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { type DependencyList, type SyntheticEvent } from 'react';
|
||||
|
||||
import { useAsyncCallback } from './affine-async-hooks';
|
||||
|
||||
export const useCatchEventCallback = <E extends SyntheticEvent>(
|
||||
cb: (e: E) => void | Promise<void>,
|
||||
deps: DependencyList
|
||||
) => {
|
||||
return useAsyncCallback(
|
||||
async (e: E) => {
|
||||
e.stopPropagation();
|
||||
await cb(e);
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
deps
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user