diff --git a/src/hooks.ts b/src/hooks.ts index 170b4e69..dc549268 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -1,11 +1,14 @@ +import { useMemo } from 'react'; import AsyncStorage from './AsyncStorage'; import type { AsyncStorageHook } from './types'; export function useAsyncStorage(key: string): AsyncStorageHook { - return { + const asyncStorage = useMemo(() => ({ getItem: (...args) => AsyncStorage.getItem(key, ...args), setItem: (...args) => AsyncStorage.setItem(key, ...args), mergeItem: (...args) => AsyncStorage.mergeItem(key, ...args), removeItem: (...args) => AsyncStorage.removeItem(key, ...args), - }; + }), [key]); + + return asyncStorage; }