1import * as React from 'react';
2import type { Client } from '@urql/core';
3
4/** Function to cache an urql-client across React Server Components.
5 *
6 * @param makeClient - A function that creates an urql-client.
7 * @returns an object containing a getClient method.
8 *
9 * @example
10 * ```ts
11 * import { cacheExchange, createClient, fetchExchange, gql } from '@urql/core';
12 * import { registerUrql } from '@urql/next/rsc';
13 * const makeClient = () => {
14 * return createClient({
15 * url: 'https://trygql.formidable.dev/graphql/basic-pokedex',
16 * exchanges: [cacheExchange, fetchExchange],
17 * });
18 * };
19 *
20 * const { getClient } = registerUrql(makeClient);
21 * ```
22 */
23export function registerUrql(makeClient: () => Client): {
24 getClient: () => Client;
25} {
26 // @ts-ignore you exist don't worry
27 const getClient = React.cache(makeClient);
28 return {
29 getClient,
30 };
31}