Skip to content

Commit

Permalink
perf(use-local-storage): add memo to deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 9, 2023
1 parent 3eda84c commit e3d4c04
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/use-local-storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'client-only';
import { useSyncExternalStore, useCallback } from 'react';
import { useSyncExternalStore, useCallback, useMemo } from 'react';
import { noop } from '../noop';
import { useIsomorphicLayoutEffect } from '../use-isomorphic-layout-effect';
import { noSSRError } from '../no-ssr';
Expand Down Expand Up @@ -134,7 +134,7 @@ export function useLocalStorage<T>(
getServerSnapshot
);

const deserialized = store === null ? null : deserializer(store);
const deserialized = useMemo(() => (store === null ? null : deserializer(store)), [store, deserializer]);

const setState = useCallback<React.Dispatch<React.SetStateAction<T | null>>>(
(v) => {
Expand Down

0 comments on commit e3d4c04

Please sign in to comment.