
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
react-select-fetch
Advanced tools
Wrapper above react-select-async-paginate that loads options from specified url
Wrapper above react-select-async-paginate that loads options from specified url.
npm install react-select react-select-async-paginate react-select-fetch
or
yarn add react-select react-select-async-paginate react-select-fetch
Abstractions are wonderful but the most common task for async select is load list of options by specified url and query params. E.g.
// With SelectFetch
import { SelectFetch } from 'react-select-fetch';
...
<SelectFetch
value={value}
url="/awesome-api-url/"
mapResponse={(response) => ({
options: response.results,
hasMore: response.has_more,
})}
onChange={setValue}
/>
// Without SelectFetch
import { AsyncPaginate } from 'react-select-async-paginate';
...
<AsyncPaginate
value={value}
loadOptions={async (search, loadedOptions, { page }) => {
const response = await fetch(`/awesome-api-url/?search=${search}&page=${page}`);
const responseJSON = await response.json();
return {
options: responseJSON.results,
hasMore: responseJSON.has_more,
additional: {
page: page + 1,
},
};
}}
onChange={setValue}
additional={{
page: 1,
}}
/>
SelectFetch receives props of react-select and react-select-async-paginate. And there are some new props:
Required. String.
Not required. Object. Object of permanent query params for requests.
Not required. String. Name of param that contains value of search input. "search" by default.
Not required. String. Name of param that contains index of loaded page. Starts from 1. "page" by default.
Not required. String. Name of param that contains number of loaded optons. "offset" by default.
Not required. Function. Mapper from server's response to format of react-select-async-paginate. Arguments:
response - response of server;
payload - object:
- `payload.search` - current search;
- `payload.prevPage` - page number before requrest;
- `payload.prevOptions` - options before request;
Not required. Page number for first request for every search. 1 by default.
Not required. Page number for first request for empty search if options or defaultOptions defined. 2 by default.
Not required. Async function. Arguments:
Should return parsed response of server.
Example with axios:
import axios from 'axios';
...
const get = async (url, params) => {
const response = await axios.get(url, {
params,
});
return response.data;
};
You can use withSelectFetch HOC.
import { withSelectFetch } from 'react-select-fetch';
...
const CustomSelectFetch = withSelectFetch(CustomSelect);
Describing type of component with extra props (example with Creatable):
import type { ReactElement } from 'react';
import type { GroupBase } from 'react-select';
import Creatable from 'react-select/creatable';
import type { CreatableProps } from 'react-select/creatable';
import type { ComponentProps } from 'react-select-async-paginate';
import { withSelectFetch } from 'react-select-fetch';
import type { UseSelectFetchParams } from 'react-select-fetch';
type SelectFetchCreatableProps<
OptionType,
Group extends GroupBase<OptionType>,
IsMulti extends boolean,
> =
& CreatableProps<OptionType, IsMulti, Group>
& UseSelectFetchParams<OptionType, Group>
& ComponentProps<OptionType, Group, IsMulti>;
type SelectFetchCreatableType = <
OptionType,
Group extends GroupBase<OptionType>,
IsMulti extends boolean = false,
>(props: SelectFetchCreatableProps<OptionType, Group, IsMulti>) => ReactElement;
const SelectFetchCreatable = withSelectFetch(Creatable) as SelectFetchCreatableType;
FAQs
Wrapper above react-select-async-paginate that loads options from specified url
The npm package react-select-fetch receives a total of 1,726 weekly downloads. As such, react-select-fetch popularity was classified as popular.
We found that react-select-fetch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.