Skip to content

Commit 9ca98bf

Browse files
authoredMar 6, 2023
Merge pull request #66 from commitd/useLocalType
fix(uselocalstate): corrects type declaration to allow function set
2 parents 6b0d4f2 + b3afbec commit 9ca98bf

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)
Please sign in to comment.