@commercetools-frontend/sdk
Version:
Tools for declarative fetching
63 lines (62 loc) • 2.87 kB
TypeScript
import { Component, JSX } from 'react';
import type { SuccessResult, HttpErrorType } from '@commercetools/sdk-client';
import type { TSdkAction } from "../../types.js";
type TSdkError = Error | HttpErrorType;
type TActionCreatorArgs = unknown[];
type State = {
isWaitingForCompletionOfFirstRequest: boolean;
requestsInFlight: number;
result?: SuccessResult['body'];
error?: TSdkError;
};
type TRenderOptions = {
isLoading: boolean;
refresh: () => Promise<void | SuccessResult['body']>;
result?: State['result'];
error?: State['error'];
};
type DispatchProps = {
dispatch: (action: TSdkAction) => Promise<SuccessResult['body']>;
};
type OwnProps = {
actionCreator: (...args: TActionCreatorArgs) => TSdkAction;
actionCreatorArgs?: TActionCreatorArgs;
shouldRefetch?: (prevArgs: TActionCreatorArgs, nextArgs: TActionCreatorArgs) => boolean;
onSuccess?: (result: SuccessResult['body']) => void;
onError?: (error: TSdkError) => void;
render: (options: TRenderOptions) => JSX.Element;
};
export type Props = DispatchProps & OwnProps;
type StaticErrorHandler = (error: TSdkError) => void;
export declare class SdkGet extends Component<Props, State> {
static displayName: string;
static errorHandler: StaticErrorHandler;
state: {
isWaitingForCompletionOfFirstRequest: boolean;
requestsInFlight: number;
result: undefined;
error: undefined;
};
isComponentMounted: boolean;
changeRequestsInFlight: (delta: number) => void;
componentDidMount(): void;
componentDidUpdate(prevProps: Props): void;
componentWillUnmount(): void;
fetch: ({ dispatch, actionCreator, actionCreatorArgs, onSuccess, onError, }: Pick<Props, "dispatch" | "actionCreator" | "actionCreatorArgs" | "onSuccess" | "onError">) => Promise<void | import("@commercetools/sdk-client").Json>;
refresh: () => Promise<void | import("@commercetools/sdk-client").Json>;
render(): JSX.Element;
}
declare const _default: import("react-redux").ConnectedComponent<typeof SdkGet, {
render: (options: TRenderOptions) => JSX.Element;
ref?: import("react").Ref<SdkGet> | undefined;
key?: import("react").Key | null | undefined;
onError?: ((error: TSdkError) => void) | undefined;
css?: import("@emotion/react").Interpolation<import("@emotion/react").Theme>;
actionCreator: (...args: TActionCreatorArgs) => TSdkAction;
actionCreatorArgs?: TActionCreatorArgs | undefined;
shouldRefetch?: ((prevArgs: TActionCreatorArgs, nextArgs: TActionCreatorArgs) => boolean) | undefined;
onSuccess?: ((result: SuccessResult["body"]) => void) | undefined;
context?: import("react").Context<import("react-redux").ReactReduxContextValue<any, import("redux").UnknownAction> | null> | undefined;
store?: import("redux").Store | undefined;
}>;
export default _default;