Skip to content

Commit 6fcf452

Browse files
committed
fix: useStorage outdated context value issue
affects: @medly-components/core, @medly-components/utils
1 parent 7e41819 commit 6fcf452

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

packages/core/src/components/SearchBox/SearchBox.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@ const Component: FC<SearchBoxProps> = memo(
7171
updateIsTyping(false);
7272
onClear?.();
7373
}, []),
74-
handleChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
75-
const { value } = event.target;
76-
updateIsTyping(value.length !== 0);
77-
setShowCloseIcon(value.length !== 0);
78-
onInputChange?.(value);
79-
}, []),
74+
handleChange = useCallback(
75+
(event: React.ChangeEvent<HTMLInputElement>) => {
76+
const { value } = event.target;
77+
updateIsTyping(value.length !== 0);
78+
setShowCloseIcon(value.length !== 0);
79+
onInputChange?.(value);
80+
},
81+
[onInputChange]
82+
),
8083
handleOptionClick = useCallback(
8184
(option: Option) => {
8285
if (inputRef.current) {

packages/utils/src/hooks/useStorage/useStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const useStorage = <T>(key: string, currOptions?: UseStorageOptions<T>):
5050
}
5151

5252
try {
53-
const newValue = value instanceof Function ? value(storedValue) : value;
53+
const newValue = value instanceof Function ? value(readValue()) : value;
5454
storage.setItem(key, newValue);
5555
isMounted.current && setStoredValue(newValue);
5656
window.dispatchEvent(new Event(`local-storage-${key}`));

0 commit comments

Comments
 (0)