Skip to main content
Version: 1.x

QraftContext

QraftContext is the default provider for the Qraft API client used to make requests using Hooks in React.

<QraftContext.Provider
value={{
requestFn,
baseUrl,
queryClient,
}}
children={children}
/>

Context Value

  • requestFn: requestFn(requestSchema, requestInfo) => Promise<T> - Required function used to make requests
  • baseUrl: string - Required base URL of the API to be used by requestFn
  • queryClient?: QueryClient - Optional QueryClient 🌴 to be used in Qraft Hooks. If not provided, useQueryClient() 🌴 result will be used as a default QueryClient.

Examples

src/APIClientProvider.tsx
import React from 'react';
import { QraftContext, requestFn } from '@openapi-qraft/react';

export default function ApplicationProviders({ children }: { children: React.ReactNode }) {
return (
<QraftContext.Provider
value={{
requestFn, // the request function to use, could be fully customized
baseUrl: 'https://petstore3.swagger.io/api/v3', // the base URL of the API
}}
>
{children}
</QraftContext.Provider>
);
}