The screenshot API for developers -
Try ScreenshotOne
Skip to content

React Native Adapter

This guide explains how to use oRPC with React Native, including the platform's supported features and current limitations.

React Native provides a built-in Fetch API, allowing you to connect to an oRPC server over HTTP. Learn more in the Fetch Client Adapter documentation.

ts
import { RPCLink } from '@orpc/client/fetch'

const link = new RPCLink({
  origin: 'https://api.example.com',
  url: '/rpc',
  headers: async ({ context }) => ({
    'x-api-key': context?.something ?? ''
  })
})

INFO

The link can be any supported oRPC link, such as RPCLink, OpenAPILink, or a custom one.

Limitations

The built-in fetch implementation in React Native does not support File/Blob/ReadableStream<Uint8Array> or AsyncIteratorObject. Follow Support Stream #27741 for progress.

If you're using Expo SDK 56 or later, with expo/fetch, you can:

INFO

expo/fetch automatically replaces the global fetch from Expo SDK 56 onward, so no action is required.

TIP

If you're using RPC Link, you can extend the RPC JSON Serializer to support additional types, including binary data, by encoding them as base64.

React Native also provides built-in WebSocket support, allowing you to connect to an oRPC server over WebSocket. Learn more in the WebSocket Client Adapter documentation.

ts
import { RPCLink } from '@orpc/client/websocket'

const link = new RPCLink({
  connect: () => new WebSocket('ws://localhost:3000'),
})

INFO

The link can be any supported oRPC link, such as RPCLink, OpenAPILink, or a custom one.

Released under the MIT License.