Skip to content

Commit 3b66dc9

Browse files
committed
fix value reset on sources
1 parent 9abe563 commit 3b66dc9

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

digitransit-component/packages/digitransit-component-autosuggest/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ function DTAutosuggest({
281281
};
282282
const [state, dispatch] = useReducer(searchReducer, initialState);
283283
// Reset the state when value or sources change, this also triggers a new search
284-
useEffect(() => dispatch({ type: 'RESET', initialState }), [value, sources]);
284+
useEffect(() => dispatch({ type: 'RESET', initialState }), [value]);
285+
useEffect(() => dispatch({ type: 'RESET_SOURCES', sources }), [sources]);
285286
// create and store input ref in the parent if storeRef is provided
286287
const inputRef = useRef(id);
287288
useEffect(() => {

digitransit-component/packages/digitransit-component-autosuggest/src/utils/searchReducer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export const searchReducer = (state, action) => {
1616
...state,
1717
suggestions: [],
1818
};
19+
case 'RESET_SOURCES':
20+
return {
21+
...state,
22+
sources: action.sources,
23+
};
1924
case 'SET_SOURCES':
2025
return {
2126
...state,

0 commit comments

Comments
 (0)