10.45.2 • Published 6 days ago

@trpc/react-query v10.45.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 days ago

@trpc/react

Connect a tRPC server to React.

Documentation

Full documentation for @trpc/react-query can be found here

Installation

# npm
npm install @trpc/react-query@next @tanstack/react-query

# Yarn
yarn add @trpc/react-query@next @tanstack/react-query

# pnpm
pnpm add @trpc/react-query@next @tanstack/react-query

Basic Example

Create a utils file that exports tRPC hooks and providers.

import { createReactQueryHooks, createTRPCReact } from '@trpc/react-query';
import type { AppRouter } from './server';

export const trpc = createTRPCReact<AppRouter>();

Use the provider to connect to your API.

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React from 'react';
import { useState } from 'react';
import { trpc } from '~/utils/trpc';

export function App() {
  const [queryClient] = useState(() => new QueryClient());
  const [trpcClient] = useState(() =>
    trpc.createClient({
      url: 'http://localhost:5000/trpc',
    }),
  );
  return (
    <trpc.Provider client={trpcClient} queryClient={queryClient}>
      <QueryClientProvider client={queryClient}>
        {/* Your app here */}
      </QueryClientProvider>
    </trpc.Provider>
  );
}

Now in any component, you can query your API using the proxy exported from the utils file.

import { proxy } from '~/utils/trpc';

export function Hello() {
  const { data, error, status } = proxy.greeting.useQuery({ name: 'tRPC' });

  if (error) {
    return <p>{error.message}</p>;
  }

  if (status !== 'success') {
    return <p>Loading...</p>;
  }

  return <div>{data && <p>{data.greeting}</p>}</div>;
}
11.0.0-rc.630

6 days ago

11.0.0-rc.621

8 days ago

11.0.0-rc.619

8 days ago

11.0.0-rc.608

15 days ago

11.0.0-rc.607

15 days ago

11.0.0-rc.599

19 days ago

11.0.0-rc.604

17 days ago

11.0.0-rc.601

18 days ago

11.0.0-rc.593

27 days ago

11.0.0-rc.592

27 days ago

11.0.0-rc.591

27 days ago

11.0.0-rc.590

27 days ago

11.0.0-rc.589

27 days ago

11.0.0-rc.588

28 days ago

11.0.0-rc.587

28 days ago

11.0.0-rc.586

30 days ago

11.0.0-rc.584

1 month ago

11.0.0-rc.580

1 month ago

11.0.0-rc.577

1 month ago

11.0.0-rc.576

1 month ago

11.0.0-rc.571

1 month ago

11.0.0-rc.569

1 month ago

11.0.0-rc.567

1 month ago

11.0.0-rc.566

1 month ago

11.0.0-rc.565

1 month ago

11.0.0-rc.563

1 month ago

11.0.0-rc.561

1 month ago

11.0.0-rc.560

1 month ago

11.0.0-rc.553

2 months ago

11.0.0-rc.552

2 months ago

11.0.0-rc.551

2 months ago

11.0.0-rc.544

2 months ago

11.0.0-rc.532

2 months ago

11.0.0-rc.531

2 months ago

11.0.0-rc.530

2 months ago

11.0.0-rc.498

3 months ago

11.0.0-rc.490

3 months ago

11.0.0-rc.489

3 months ago

11.0.0-rc.487

3 months ago

11.0.0-rc.528

2 months ago

11.0.0-rc.524

2 months ago

11.0.0-rc.522

2 months ago

11.0.0-rc.521

2 months ago

11.0.0-rc.520

2 months ago

11.0.0-rc.502

2 months ago

11.0.0-rc.501

2 months ago

11.0.0-rc.500

2 months ago

11.0.0-rc.485

3 months ago

11.0.0-rc.482

3 months ago

11.0.0-rc.480

3 months ago

11.0.0-rc.383

6 months ago

11.0.0-rc.382

6 months ago

11.0.0-rc.377

6 months ago

11.0.0-rc.477

4 months ago

11.0.0-rc.475

4 months ago

11.0.0-rc.474

4 months ago

11.0.0-rc.467

4 months ago

11.0.0-rc.466

4 months ago

11.0.0-rc.465

4 months ago

11.0.0-rc.461

4 months ago

11.0.0-rc.460

4 months ago

11.0.0-rc.459

4 months ago

11.0.0-rc.458

4 months ago

11.0.0-rc.456

4 months ago

11.0.0-rc.455

4 months ago

11.0.0-rc.452

4 months ago

11.0.0-rc.449

4 months ago

11.0.0-rc.446

4 months ago

11.0.0-rc.445

4 months ago

11.0.0-rc.444

5 months ago

11.0.0-rc.441

5 months ago

11.0.0-rc.439

5 months ago

11.0.0-rc.436

5 months ago

11.0.0-rc.435

5 months ago

11.0.0-rc.433

5 months ago

11.0.0-rc.432

5 months ago

11.0.0-rc.421

5 months ago

11.0.0-rc.419

5 months ago

11.0.0-rc.417

5 months ago

11.0.0-rc.413

5 months ago

11.0.0-rc.403

5 months ago

11.0.0-rc.402

5 months ago

11.0.0-rc.401

5 months ago

11.0.0-rc.396

5 months ago

11.0.0-rc.394

5 months ago

11.0.0-rc.390

6 months ago

11.0.0-rc.374

6 months ago

11.0.0-rc.373

6 months ago

11.0.0-rc.370

6 months ago

11.0.0-rc.369

6 months ago

11.0.0-rc.366

6 months ago

11.0.0-rc.364

7 months ago

11.0.0-rc.363

7 months ago

11.0.0-rc.362

7 months ago

11.0.0-rc.361

7 months ago

11.0.0-rc.359

7 months ago

11.0.0-rc.354

7 months ago

11.0.0-rc.351

7 months ago

11.0.0-rc.348

7 months ago

11.0.0-rc.347

7 months ago

11.0.0-rc.346

7 months ago

11.0.0-rc.345

7 months ago

11.0.0-rc.342

7 months ago

11.0.0-rc.340

7 months ago

11.0.0-rc.334

7 months ago

11.0.0-rc.332

8 months ago

11.0.0-rc.330

8 months ago

11.0.0-rc.329

8 months ago

11.0.0-next.326

8 months ago

11.0.0-next.325

8 months ago

11.0.0-next.327

8 months ago

11.0.0-next.322

8 months ago

11.0.0-next.324

8 months ago

11.0.0-next.323

8 months ago

11.0.0-next.320

8 months ago

10.45.2

8 months ago

10.45.2-canary.0

8 months ago

10.45.1

9 months ago

10.45.1-canary.24

10 months ago

10.45.1-canary.23

10 months ago

10.45.1-canary.20

10 months ago

10.45.1-canary.17

10 months ago

10.45.1-canary.16

10 months ago

10.45.1-canary.13

11 months ago

10.45.1-canary.11

11 months ago

10.45.1-canary.9

11 months ago

10.45.1-canary.8

11 months ago

10.45.0

11 months ago

10.45.1-canary.1

11 months ago

10.45.1-canary.0

11 months ago

10.45.1-canary.3

11 months ago

10.45.1-canary.2

11 months ago

10.45.1-canary.4

11 months ago

10.44.2-canary.30

11 months ago

10.44.2-canary.32

11 months ago

10.44.2-canary.31

11 months ago

10.44.2-canary.34

11 months ago

10.44.2-canary.33

11 months ago

10.44.2-canary.37

11 months ago

11.0.0-alpha.131

11 months ago

10.41.0

1 year ago

10.38.1

1 year ago

10.38.0

1 year ago

10.38.3

1 year ago

10.38.2

1 year ago

10.38.5

1 year ago

10.38.4

1 year ago

10.42.0

1 year ago

10.39.0

1 year ago

10.36.0

1 year ago

10.40.0

1 year ago

10.37.0

1 year ago

10.37.1

1 year ago

10.34.1

1 year ago

10.34.0

1 year ago

10.35.0

1 year ago

10.43.5

12 months ago

10.43.4

1 year ago

10.43.7

12 months ago

10.43.6

12 months ago

10.43.1

1 year ago

10.43.0

1 year ago

10.43.3

1 year ago

10.43.2

1 year ago

11.0.0-next.92

1 year ago

11.0.0-next.91

1 year ago

10.44.0

12 months ago

10.44.1

12 months ago

10.33.1

1 year ago

10.33.0

1 year ago

10.30.0

1 year ago

10.32.0

1 year ago

10.31.0

1 year ago

10.28.0

1 year ago

10.26.0

2 years ago

10.24.0

2 years ago

10.28.1

1 year ago

10.28.2

1 year ago

10.27.0

1 year ago

10.27.1

1 year ago

10.25.0

2 years ago

10.25.1

2 years ago

10.23.1

2 years ago

10.29.0

1 year ago

10.27.2

1 year ago

10.29.1

1 year ago

10.27.3

1 year ago

10.21.3-alpha.3

2 years ago

10.21.3-alpha.2

2 years ago

10.21.3-alpha.9

2 years ago

10.21.3-alpha.8

2 years ago

10.21.3-alpha.7

2 years ago

10.22.0

2 years ago

10.21.3-alpha.1

2 years ago

10.21.1-alpha.2

2 years ago

10.21.1-alpha.1

2 years ago

10.21.1-alpha.0

2 years ago

10.21.3-test.0

2 years ago

10.23.0

2 years ago

10.21.2

2 years ago

10.21.0

2 years ago

10.21.1

2 years ago

10.20.0

2 years ago

10.17.0

2 years ago

10.15.0

2 years ago

10.19.1

2 years ago

10.19.0

2 years ago

10.16.0

2 years ago

10.14.1

2 years ago

10.18.0

2 years ago

10.14.0

2 years ago

10.13.1

2 years ago

10.13.2

2 years ago

10.13.0

2 years ago

10.12.0

2 years ago

10.9.1

2 years ago

10.11.1

2 years ago

10.10.0

2 years ago

10.11.0

2 years ago

10.5.0

2 years ago

10.6.0

2 years ago

10.7.0

2 years ago

10.8.0

2 years ago

10.9.0

2 years ago

10.8.1

2 years ago

10.8.2

2 years ago

10.4.3

2 years ago

10.4.2

2 years ago

10.4.1

2 years ago

10.4.0

2 years ago

10.3.0

2 years ago

10.2.0

2 years ago

10.1.0

2 years ago

10.0.0

2 years ago

10.0.0-rc.9

2 years ago

10.0.0-rc.8

2 years ago

10.0.0-rc.7

2 years ago

10.0.0-rc.6

2 years ago

10.0.0-rc.5

2 years ago

10.0.0-rc.4

2 years ago

10.0.0-rc.3

2 years ago

10.0.0-rc.2

2 years ago

10.0.0-rc.1

2 years ago

10.0.0-rc.0

2 years ago