Skip to content

perf(createUseStorageState): remove optional chaining #2241

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

Merged
merged 2 commits into from
Jul 5, 2023
Merged
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
14 changes: 7 additions & 7 deletions packages/hooks/src/createUseStorageState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ export function createUseStorageState(getStorage: () => Storage | undefined) {
}

const serializer = (value: T) => {
if (options?.serializer) {
return options?.serializer(value);
if (options.serializer) {
return options.serializer(value);
}
return JSON.stringify(value);
};

const deserializer = (value: string): T => {
if (options?.deserializer) {
return options?.deserializer(value);
if (options.deserializer) {
return options.deserializer(value);
}
return JSON.parse(value);
};
Expand All @@ -57,10 +57,10 @@ export function createUseStorageState(getStorage: () => Storage | undefined) {
} catch (e) {
onError(e);
}
if (isFunction(options?.defaultValue)) {
return options?.defaultValue();
if (isFunction(options.defaultValue)) {
return options.defaultValue();
}
return options?.defaultValue;
return options.defaultValue;
}

const [state, setState] = useState(() => getStoredValue());
Expand Down