Gathering detailed insights and metrics for react-select-async-paginate
Gathering detailed insights and metrics for react-select-async-paginate
Gathering detailed insights and metrics for react-select-async-paginate
Gathering detailed insights and metrics for react-select-async-paginate
react-select-fetch
Wrapper above react-select-async-paginate that loads options from specified url
@turtletongue/react-select-async-paginate
Wrapper above react-select that supports pagination on menu scroll
react-select-async-paginate-sf2
Wrapper above react-select that supports pagination on menu scroll
react-select-async-paginate-self
Wrapper above react-select that supports pagination on menu scroll
Wrapper above react-select that supports pagination on menu scroll
npm install react-select-async-paginate
Typescript
Module System
Node Version
NPM Version
79.6
Supply Chain
88.5
Quality
83.2
Maintenance
100
Vulnerability
99.6
License
TypeScript (100%)
Total Downloads
16,781,969
Last Day
13,637
Last Week
103,977
Last Month
513,375
Last Year
5,923,205
311 Stars
336 Commits
75 Forks
8 Watching
4 Branches
11 Contributors
Minified
Minified + Gzipped
Latest Version
0.7.7
Package Id
react-select-async-paginate@0.7.7
Unpacked Size
110.51 kB
Size
15.34 kB
File Count
8
NPM Version
10.8.2
Node Version
20.18.0
Publised On
06 Dec 2024
Cumulative downloads
Total Downloads
Last day
-46%
13,637
Compared to previous day
Last week
-17.7%
103,977
Compared to previous week
Last month
2.8%
513,375
Compared to previous month
Last year
40.3%
5,923,205
Compared to previous year
Wrapper above react-select
that supports pagination on menu scroll.
react-select | react-select-async-paginate |
---|---|
5.x | 0.6.x, 0.7.x |
4.x | 0.5.x |
3.x | 0.5.x, 0.4.x, ^0.3.2 |
2.x | 0.3.x, 0.2.x |
1.x | 0.1.x |
npm install react-select react-select-async-paginate
or
yarn add react-select react-select-async-paginate
AsyncPaginate
is an alternative of Async
but supports loading page by page. It is wrapper above default react-select
thus it accepts all props of default Select
. And there are some new props:
Required. Async function that take next arguments:
additional
from props, for next is additional
from previous response for current search. null
by default.It should return next object:
{
options: Array,
hasMore: boolean,
additional?: any,
}
It similar to loadOptions
from Select.Async
but there is some differences:
hasMore
for detect end of options list for current search.Not required. Number. Debounce timeout for loadOptions
calls. 0
by default.
Not required. Default additional
for first request for every search.
Not required. Default additional
for empty search if options
or defaultOptions
defined.
Not required. Function. By default new options will load only after scroll menu to bottom. Arguments:
Should return boolean.
Not required. Function. By default new loaded options are concat with previous. Arguments:
Should return new options.
Not required. Number. Time in milliseconds to retry a request after an error
Not required. Array. Works as 2nd argument of useEffect
hook. When one of items changed, AsyncPaginate
cleans all cached options.
Not required. Boolean. If false
options will not load on menu opening.
Ref for take react-select
instance.
1import { AsyncPaginate } from 'react-select-async-paginate'; 2 3... 4 5/* 6 * assuming the API returns something like this: 7 * const json = { 8 * results: [ 9 * { 10 * value: 1, 11 * label: 'Audi', 12 * }, 13 * { 14 * value: 2, 15 * label: 'Mercedes', 16 * }, 17 * { 18 * value: 3, 19 * label: 'BMW', 20 * }, 21 * ], 22 * has_more: true, 23 * }; 24 */ 25 26async function loadOptions(search, loadedOptions) { 27 const response = await fetch(`/awesome-api-url/?search=${search}&offset=${loadedOptions.length}`); 28 const responseJSON = await response.json(); 29 30 return { 31 options: responseJSON.results, 32 hasMore: responseJSON.has_more, 33 }; 34} 35 36<AsyncPaginate 37 value={value} 38 loadOptions={loadOptions} 39 onChange={setValue} 40/>
1import { AsyncPaginate } from 'react-select-async-paginate'; 2 3... 4 5async function loadOptions(search, loadedOptions, { page }) { 6 const response = await fetch(`/awesome-api-url/?search=${search}&page=${page}`); 7 const responseJSON = await response.json(); 8 9 return { 10 options: responseJSON.results, 11 hasMore: responseJSON.has_more, 12 additional: { 13 page: page + 1, 14 }, 15 }; 16} 17 18<AsyncPaginate 19 value={value} 20 loadOptions={loadOptions} 21 onChange={setValue} 22 additional={{ 23 page: 1, 24 }} 25/>
You can use reduceGroupedOptions
util to group options by label
key.
1import { AsyncPaginate, reduceGroupedOptions } from 'react-select-async-paginate'; 2 3/* 4 * assuming the API returns something like this: 5 * const json = { 6 * options: [ 7 * label: 'Cars', 8 * options: [ 9 * { 10 * value: 1, 11 * label: 'Audi', 12 * }, 13 * { 14 * value: 2, 15 * label: 'Mercedes', 16 * }, 17 * { 18 * value: 3, 19 * label: 'BMW', 20 * }, 21 * ] 22 * ], 23 * hasMore: true, 24 * }; 25 */ 26 27... 28 29<AsyncPaginate 30 {...otherProps} 31 reduceOptions={reduceGroupedOptions} 32/>
You can use withAsyncPaginate
HOC.
1import { withAsyncPaginate } from 'react-select-async-paginate'; 2 3... 4 5const CustomAsyncPaginate = withAsyncPaginate(CustomSelect);
Describing type of component with extra props (example with Creatable
):
1import type { ReactElement } from 'react'; 2import type { GroupBase } from 'react-select'; 3import Creatable from 'react-select/creatable'; 4import type { CreatableProps } from 'react-select/creatable'; 5 6import { withAsyncPaginate } from 'react-select-async-paginate'; 7import type { 8 UseAsyncPaginateParams, 9 ComponentProps, 10} from 'react-select-async-paginate'; 11 12type AsyncPaginateCreatableProps< 13OptionType, 14Group extends GroupBase<OptionType>, 15Additional, 16IsMulti extends boolean, 17> = 18 & CreatableProps<OptionType, IsMulti, Group> 19 & UseAsyncPaginateParams<OptionType, Group, Additional> 20 & ComponentProps<OptionType, Group, IsMulti>; 21 22type AsyncPaginateCreatableType = < 23OptionType, 24Group extends GroupBase<OptionType>, 25Additional, 26IsMulti extends boolean = false, 27>(props: AsyncPaginateCreatableProps<OptionType, Group, Additional, IsMulti>) => ReactElement; 28 29const AsyncPaginateCreatable = withAsyncPaginate(Creatable) as AsyncPaginateCreatableType;
Usage of replacing components is similar with react-select
, but there is one difference. If you redefine MenuList
you should wrap it with wrapMenuList
for workaround of some internal bugs of react-select
.
1import { AsyncPaginate, wrapMenuList } from 'react-select-async-paginate'; 2 3... 4 5const MenuList = wrapMenuList(CustomMenuList); 6 7<AsyncPaginate 8 {...otherProps} 9 components={{ 10 ...otherComponents, 11 MenuList, 12 }} 13/>
If you want construct own component that uses logic of react-select-async-paginate
inside, you can use next hooks:
useAsyncPaginate
useAsyncPaginateBase
useComponents
1import { 2 useAsyncPaginate, 3 useComponents, 4} from 'react-select-async-paginate'; 5 6... 7 8const CustomAsyncPaginateComponent = ({ 9 options, 10 defaultOptions, 11 additional, 12 loadOptionsOnMenuOpen, 13 debounceTimeout, 14 filterOption, 15 reduceOptions, 16 shouldLoadMore, 17 18 components: defaultComponents, 19 20 value, 21 onChange, 22}) => { 23 const asyncPaginateProps = useAsyncPaginate({ 24 options, 25 defaultOptions, 26 additional, 27 loadOptionsOnMenuOpen, 28 debounceTimeout, 29 filterOption, 30 reduceOptions, 31 shouldLoadMore, 32 }); 33 34 const components = useComponents(defaultComponents); 35 36 return ( 37 <CustomSelect 38 {...asyncPaginateProps} 39 components={components} 40 value={value} 41 onChange={onChange} 42 /> 43 ); 44}
useComponents
provides redefined MenuList
component by default. If you want redefine it, you should also wrap in with wrapMenuList
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
4 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 4
Reason
Found 3/18 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More