Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: createUseStorageState 3.7.7 以上版本返回 undefined 类型问题 #2681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/hooks/src/createUseStorageState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function createUseStorageState(getStorage: () => Storage | undefined) {
return JSON.stringify(value);
};

const deserializer = (value: string): T => {
const deserializer = (value: string) => {
if (options.deserializer) {
return options.deserializer(value);
}
Expand All @@ -62,13 +62,13 @@ export function createUseStorageState(getStorage: () => Storage | undefined) {
return options.defaultValue;
}

const [state, setState] = useState(getStoredValue);
const [state, setState] = useState<T>(getStoredValue);

useUpdateEffect(() => {
setState(getStoredValue());
}, [key]);

const updateState = (value?: SetState<T>) => {
const updateState = (value: SetState<T>) => {
const currentState = isFunction(value) ? value(state) : value;

if (!listenStorageChange) {
Expand Down