Skip to content

Commit b3afbec

Browse files
committed
fix(uselocalstate): corrects type declaration to allow function style set
adds SetStateAction to the exported setValue type - it already satisfies this but was not types that way.
1 parent 6b0d4f2 commit b3afbec

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/useLocalState/useLocalState.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Dispatch, useCallback, useEffect, useRef, useState } from 'react'
1+
import {
2+
Dispatch,
3+
SetStateAction,
4+
useCallback,
5+
useEffect,
6+
useRef,
7+
useState,
8+
} from 'react'
29

310
/**
411
* Serialize the value to a string
@@ -38,7 +45,7 @@ export function useLocalState<T>(
3845
serialize: Serializer<T>
3946
deserialize: Deserializer<T>
4047
} = { serialize: JSON.stringify, deserialize: JSON.parse }
41-
): [T, Dispatch<T>, () => void] {
48+
): [T, Dispatch<SetStateAction<T>>, () => void] {
4249
const [state, setState] = useState<T>(() => {
4350
const valueInLocalStorage = window.localStorage.getItem(key)
4451
if (valueInLocalStorage != null) {

0 commit comments

Comments
 (0)