From 43b68d427a2f26a26a96bae7029660e36cd12887 Mon Sep 17 00:00:00 2001 From: memeriau Date: Mon, 18 Apr 2022 00:21:33 +0200 Subject: [PATCH] add useMemo to useAction --- src/utils/useAction.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils/useAction.ts b/src/utils/useAction.ts index 31a070d..6420f7a 100644 --- a/src/utils/useAction.ts +++ b/src/utils/useAction.ts @@ -1,11 +1,16 @@ import { useDispatch } from "react-redux" +import { useMemo } from "react" const useAction = (action: (...args: any[]) => any): any => { const dispatch = useDispatch() - return (...args: any[]) => { - dispatch(action(...args)) - } + return useMemo( + () => + (...args: any[]) => { + dispatch(action(...args)) + }, + [dispatch, action] + ) } export default useAction