React Native Guide
Use the library with the Fetch implementation provided by your React Native runtime.
New Architecture & Bridgeless Compatibility
The package delegates network requests to globalThis.fetch by default. It does not ship a platform-specific networking module, so the Fetch features available depend on the React Native runtime and version used by your app.
If your environment needs a different transport, provide a compatible fetchImpl when you create the client. Check that the runtime also provides the Fetch APIs needed by the features you use, such as streams for streaming and progress callbacks.
Runtime APIs
The package itself has no native networking module. Your app's React Native runtime still determines which Fetch APIs are available.
Using a storage adapter with a key-value store
The cache accepts a key-value adapter. This example shows how to connect an app storage instance; install and configure your storage library according to its own documentation:
src/api.ts
typescript
import { createClient, type CacheStorageAdapter } from 'react-native-fetch-client';
// Adapt your app's key-value store to this interface.
const cacheStorage: CacheStorageAdapter = {
getItem: (key) => appStore.getItem(key),
setItem: (key, value) => appStore.setItem(key, value),
removeItem: (key) => appStore.removeItem(key),
};
export const api = createClient({
baseURL: 'https://api.example.com',
cache: {
enabled: true,
storage: cacheStorage,
ttl: 1000 * 60 * 15, // 15 minutes
},
});