Skip to content
module@warp-drive/react

Interface RequestProps<RT, E> ​

ts
interface RequestProps<RT, E> extends RequestArgs<RT, E> {
  chrome?: FC<ChromeComponentProps<RT>>;
  states: RequestStates<RT, E>;
}

Defined in: -private/request.tsx:123

The props accepted by the `<Request />` component.

states is required. Every other prop is optional, but either request or query is needed for the component to leave the idle state, and a store must be available via the store prop or a StoreProvider.

PropTypePurpose
statesRequestStatesThe components to render for each state
requestFutureA request already made via store.request to monitor
queryStoreRequestInputA request for the component to make and monitor
storeStore or RequestManagerThe store to make requests with
subscriptionRequestSubscriptionA subscription to render in place of creating one
autorefreshboolean or stringWhen to automatically refresh the request
autorefreshThresholdnumberHow long in ms before an autorefresh happens
autorefreshBehavior'refresh', 'reload' or 'policy'How autorefresh fetches
chromeReact.FCA component that wraps every state's component

All but states and chrome are inherited from RequestArgs and documented on the members below.

Example ​

tsx
import { Request } from "@warp-drive/react";
import { findRecord } from "@warp-drive/utilities/json-api";

export function UserName({ id }: { id: string }) {
  return (
    <Request
      query={findRecord("user", id)}
      autorefresh="online,interval"
      autorefreshThreshold={60_000}
      autorefreshBehavior="refresh"
      states={{
        content: ({ result }) => <>{result.data.name}</>,
        error: ({ error }) => <>{error.message}</>,
      }}
    />
  );
}

Extends ​

  • RequestArgs<RT, E>

Type Parameters ​

RT ​

RT

E ​

E

Properties ​

chrome? ​

ts
optional chrome?: FC<ChromeComponentProps<RT>>;

Defined in: -private/request.tsx:138

A component that wraps whichever state component is rendered, so shared UI such as a layout or a refresh indicator stays mounted as the request moves between states. It renders its children where the state's component renders, and receives the ChromeComponentProps.

tsx
function Chrome({ children, features }: ChromeComponentProps<User>) {
  return <div className={features.isRefreshing ? "is-refreshing" : ""}>{children}</div>;
}

<Request request={request} chrome={Chrome} states={states} />

states ​

ts
states: RequestStates<RT, E>;

Defined in: -private/request.tsx:144

The components to render for each state of the request, see RequestStates.

Released under the MIT License.