Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/react-select-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"react-select-async-paginate": "^0.7.0"
},
"dependencies": {
"krustykrab": "^1.1.0",
"qs": "^6.14.0"
},
"devDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion packages/react-select-fetch/src/get.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { stringifyParams } from "./stringifyParams";

export const get = async (
url: string,
url: string|undefined,
params: Record<string, unknown>,
): Promise<unknown> => {
if (url == null) {
throw new Error("The `url` prop is required unless `get` is overridden.")
}
const paramsStr = stringifyParams(params);

const response: Response = await fetch(`${url}?${paramsStr}`, {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it would be better to do url ?? '' instead of throwing an error above.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this different from setting url = "" default here?

I'd decided on throwing an error because it was least surprising compared to the previous behavior of throwing an inspection error.

I think I also might have found a minimal change with no associated functional code that would do it:

export type UseSelectFetchMapParams<
	OptionType,
	Group extends GroupBase<OptionType>,
> = ({ url: string, get: never} | {get: Get, url: never}) & {
	queryParams?: {
		[key: string]: unknown;
	};
	searchParamName?: string | null;
	pageParamName?: string | null;
	offsetParamName?: string | null;
	mapResponse?: MapResponse<OptionType, Group>;
	initialPage?: number;
	defaultInitialPage?: number;
};

I think this means we can have url xor get?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library aims to provide a convenient way to work with api endpoints. get is supposed to provide headers to request.

What is your case and why don't you use react-select-async-paginate for it?

Expand Down
4 changes: 2 additions & 2 deletions packages/react-select-fetch/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type MapResponse<OptionType, Group extends GroupBase<OptionType>> = (
) => Response<OptionType, Group, Additional>;

export type Get = <Response>(
url: string,
url: string|undefined,
params: {
[key: string]: unknown;
},
Expand All @@ -40,7 +40,7 @@ export type UseSelectFetchMapParams<
OptionType,
Group extends GroupBase<OptionType>,
> = {
url: string;
url?: string;
queryParams?: {
[key: string]: unknown;
};
Expand Down
1 change: 0 additions & 1 deletion packages/react-select-fetch/src/useMapToAsyncPaginate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getResult } from "krustykrab";
import { useCallback, useMemo } from "react";
import type { GroupBase } from "react-select";
import { checkIsResponse } from "react-select-async-paginate";
Expand Down