Skip to content

Commit

Permalink
fix(base-select): lazy loading (#831)
Browse files Browse the repository at this point in the history
* fix(select): remove wron prop passed into renderOption method

* fix(select): do not increment offset when there are no items fetched

* fix(select): add reset callback into useLazyLoading hook

Co-authored-by: Andrew Kvashuk <avkvashuk@alfabank.ru>
  • Loading branch information
Andrey Kvashuk and Andrew Kvashuk committed Sep 8, 2021
1 parent 1d8171c commit 78f2b86
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/select/src/presets/useLazyLoading/hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const actions = {
setQueryString(qs: string) {
return { type: 'SET_QUERY_STRING', payload: qs } as const;
},
reset() {
return { type: 'RESET' } as const;
},
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -121,6 +124,11 @@ export function useLazyLoading({
queryString: action.payload,
};
}
case 'RESET': {
return {
...lazyLoadingInitialState,
};
}
default: {
return state;
}
Expand Down Expand Up @@ -265,6 +273,10 @@ export function useLazyLoading({
}));
}, [loading, limit, skeleton]);

const reset = useCallback(() => {
dispatch(actions.reset());
}, []);

return {
optionsProps: {
Option: renderOption,
Expand All @@ -278,5 +290,6 @@ export function useLazyLoading({
},
onOpen,
},
reset,
};
}

0 comments on commit 78f2b86

Please sign in to comment.