Skip to content

Commit

Permalink
fix(useMemoize): allow number in getKey (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaii3 committed Aug 23, 2022
1 parent 201eb82 commit 06ad02b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/useMemoize/index.test.ts
Expand Up @@ -159,7 +159,7 @@ describe('useMemoize', () => {

resolver.mockClear()
expect(memo(3)).toBe('result-1')
expect(memo(4)).toBe('result-2')
expect(memo('4')).toBe('result-2')
expect(resolver).not.toHaveBeenCalled()
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/core/useMemoize/index.ts
Expand Up @@ -77,7 +77,7 @@ export interface UseMemoizeReturn <Result, Args extends unknown[]> {
}

export interface UseMemoizeOptions<Result, Args extends unknown[]> {
getKey?: (...args: Args) => string
getKey?: (...args: Args) => string | number
cache?: UseMemoizeCache<CacheKey, Result>
}

Expand Down Expand Up @@ -109,7 +109,7 @@ export function useMemoize<Result, Args extends unknown[]>(
/**
* Load data and save in cache
*/
const _loadData = (key: string, ...args: Args): Result => {
const _loadData = (key: string | number, ...args: Args): Result => {
cache.set(key, resolver(...args))
return cache.get(key) as Result
}
Expand Down

0 comments on commit 06ad02b

Please sign in to comment.