From 1d5cd10fe4d031cb2c2daa0b44b8273fbe2f4040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=96=E5=AE=B6?= <576679268@qq.com> Date: Mon, 12 Aug 2019 23:39:59 +0800 Subject: [PATCH] fix: useUpdateEffect run on the wrong time --- src/useUpdateEffect.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/useUpdateEffect.ts b/src/useUpdateEffect.ts index f4f5661954..47678266bc 100644 --- a/src/useUpdateEffect.ts +++ b/src/useUpdateEffect.ts @@ -3,14 +3,13 @@ import { useEffect, useRef } from 'react'; const useUpdateEffect: typeof useEffect = (effect, deps) => { const isInitialMount = useRef(true); - useEffect( - isInitialMount.current - ? () => { - isInitialMount.current = false; - } - : effect, - deps - ); + useEffect(() => { + if (isInitialMount.current) { + isInitialMount.current = false; + } else { + effect(); + } + }, deps); }; export default useUpdateEffect;