Fix useLocalStorage types for functional updates

Fixes #438
This commit is contained in:
Charles-Axel Dein 2019-07-04 09:51:25 +02:00 committed by GitHub
parent a247692fd6
commit 5f5376c64e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,10 @@
import { useEffect, useState } from 'react';
import { isClient } from './util';
const useLocalStorage = <T>(key: string, initialValue?: T, raw?: boolean): [T, (value: T) => void] => {
type Dispatch<A> = (value: A) => void;
type SetStateAction<S> = S | ((prevState: S) => S);
const useLocalStorage = <T>(key: string, initialValue?: T, raw?: boolean): [T, Dispatch<SetStateAction<T>>] => {
if (!isClient) {
return [initialValue as T, () => {}];
}