From a01a7ede9e6b393c274450a98e293f2f719ae691 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sun, 15 May 2022 01:15:54 +0800 Subject: [PATCH] refactor: memoize useStateIO --- src/utils/hooks/useStateIO.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/hooks/useStateIO.ts b/src/utils/hooks/useStateIO.ts index f216a50..979e750 100644 --- a/src/utils/hooks/useStateIO.ts +++ b/src/utils/hooks/useStateIO.ts @@ -1,11 +1,9 @@ import * as React from 'react' -export function useStateIO( - initialState: S | (() => S), -): { +export function useStateIO(initialState: S | (() => S)): { value: S onChange: React.Dispatch> } { const [value, onChange] = React.useState(initialState) - return { value, onChange } + return React.useMemo(() => ({ value, onChange }), [value]) }