Skip to content

Commit 21739b4

Browse files
author
Eunjae Lee
authored
feat(onStateChange): provide prevState (#335)
1 parent a20887d commit 21739b4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/autocomplete-core/src/createStore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function createStore<TItem>(
2525
return state;
2626
},
2727
send(action, payload) {
28+
const prevState = { ...state };
2829
state = enhanceState(
2930
reducer(state, {
3031
type: action,
@@ -33,7 +34,7 @@ export function createStore<TItem>(
3334
})
3435
);
3536

36-
props.onStateChange({ state });
37+
props.onStateChange({ state, prevState });
3738
},
3839
};
3940
}

packages/autocomplete-core/src/types/api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ export interface AutocompleteOptions<TItem> {
198198
/**
199199
* Function called when the internal state changes.
200200
*/
201-
onStateChange?<TItem>(props: { state: AutocompleteState<TItem> }): void;
201+
onStateChange?<TItem>(props: {
202+
state: AutocompleteState<TItem>;
203+
prevState: AutocompleteState<TItem>;
204+
}): void;
202205
/**
203206
* The text that appears in the search box input when there is no query.
204207
*/
@@ -282,7 +285,10 @@ export interface InternalAutocompleteOptions<TItem>
282285
extends AutocompleteOptions<TItem> {
283286
debug: boolean;
284287
id: string;
285-
onStateChange<TItem>(props: { state: AutocompleteState<TItem> }): void;
288+
onStateChange<TItem>(props: {
289+
state: AutocompleteState<TItem>;
290+
prevState: AutocompleteState<TItem>;
291+
}): void;
286292
placeholder: string;
287293
autoFocus: boolean;
288294
defaultHighlightedIndex: number | null;

0 commit comments

Comments
 (0)