From 83f4c466b0c0da72dc5e8a1804270d123077aea9 Mon Sep 17 00:00:00 2001 From: Alexey Bojhev <9medved@mail.ru> Date: Sat, 18 Jan 2020 21:20:05 +0300 Subject: [PATCH] Typings for `useDefault` Added generic type for `useDefault` state --- src/useDefault.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/useDefault.ts b/src/useDefault.ts index c552949b26..108ac52289 100644 --- a/src/useDefault.ts +++ b/src/useDefault.ts @@ -1,13 +1,13 @@ import { useState } from 'react'; -const useDefault = (defaultValue, initialValue): [any, (nextValue?: any) => void] => { - const [value, setValue] = useState(initialValue); +const useDefault = (defaultValue: TStateType, initialValue: TStateType | (() => TStateType)) => { + const [value, setValue] = useState(initialValue); if (value === undefined || value === null) { - return [defaultValue, setValue]; + return [defaultValue, setValue] as const; } - return [value, setValue]; + return [value, setValue] as const; }; export default useDefault;