From 5f5376c64ebd318fffc76eec768ce047ddf9e300 Mon Sep 17 00:00:00 2001 From: Charles-Axel Dein Date: Thu, 4 Jul 2019 09:51:25 +0200 Subject: [PATCH] Fix useLocalStorage types for functional updates Fixes #438 --- src/useLocalStorage.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/useLocalStorage.ts b/src/useLocalStorage.ts index 03ba9392..051685be 100644 --- a/src/useLocalStorage.ts +++ b/src/useLocalStorage.ts @@ -1,7 +1,10 @@ import { useEffect, useState } from 'react'; import { isClient } from './util'; -const useLocalStorage = (key: string, initialValue?: T, raw?: boolean): [T, (value: T) => void] => { +type Dispatch = (value: A) => void; +type SetStateAction = S | ((prevState: S) => S); + +const useLocalStorage = (key: string, initialValue?: T, raw?: boolean): [T, Dispatch>] => { if (!isClient) { return [initialValue as T, () => {}]; }