10.45.2 • Published 5 days ago

@trpc/react-query v10.45.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 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.666

5 days ago

11.0.0-rc.660

15 days ago

11.0.0-rc.659

15 days ago

11.0.0-rc.657

16 days ago

11.0.0-rc.648

26 days ago

11.0.0-rc.645

27 days ago

11.0.0-rc.643

30 days ago

11.0.0-rc.642

30 days ago

11.0.0-rc.638

1 month ago

11.0.0-rc.637

1 month ago

11.0.0-rc.633

1 month ago

11.0.0-rc.632

1 month ago

11.0.0-rc.630

1 month ago

11.0.0-rc.621

1 month ago

11.0.0-rc.619

1 month ago

11.0.0-rc.608

2 months ago

11.0.0-rc.607

2 months ago

11.0.0-rc.599

2 months ago

11.0.0-rc.604

2 months ago

11.0.0-rc.601

2 months ago

11.0.0-rc.593

2 months ago

11.0.0-rc.592

2 months ago

11.0.0-rc.591

2 months ago

11.0.0-rc.590

2 months ago

11.0.0-rc.589

2 months ago

11.0.0-rc.588

2 months ago

11.0.0-rc.587

2 months ago

11.0.0-rc.586

2 months ago

11.0.0-rc.584

2 months ago

11.0.0-rc.580

2 months ago

11.0.0-rc.577

2 months ago

11.0.0-rc.576

2 months ago

11.0.0-rc.571

2 months ago

11.0.0-rc.569

2 months ago

11.0.0-rc.567

2 months ago

11.0.0-rc.566

3 months ago

11.0.0-rc.565

3 months ago

11.0.0-rc.563

3 months ago

11.0.0-rc.561

3 months ago

11.0.0-rc.560

3 months ago

11.0.0-rc.553

3 months ago

11.0.0-rc.552

3 months ago

11.0.0-rc.551

3 months ago

11.0.0-rc.544

3 months ago

11.0.0-rc.532

3 months ago

11.0.0-rc.531

3 months ago

11.0.0-rc.530

3 months ago

11.0.0-rc.498

4 months ago

11.0.0-rc.490

4 months ago

11.0.0-rc.489

4 months ago

11.0.0-rc.487

4 months ago

11.0.0-rc.528

3 months ago

11.0.0-rc.524

3 months ago

11.0.0-rc.522

3 months ago

11.0.0-rc.521

3 months ago

11.0.0-rc.520

3 months ago

11.0.0-rc.502

4 months ago

11.0.0-rc.501

4 months ago

11.0.0-rc.500

4 months ago

11.0.0-rc.485

4 months ago

11.0.0-rc.482

4 months ago

11.0.0-rc.480

4 months ago

11.0.0-rc.383

7 months ago

11.0.0-rc.382

7 months ago

11.0.0-rc.377

7 months ago

11.0.0-rc.477

5 months ago

11.0.0-rc.475

5 months ago

11.0.0-rc.474

5 months ago

11.0.0-rc.467

5 months ago

11.0.0-rc.466

5 months ago

11.0.0-rc.465

5 months ago

11.0.0-rc.461

5 months ago

11.0.0-rc.460

5 months ago

11.0.0-rc.459

5 months ago

11.0.0-rc.458

5 months ago

11.0.0-rc.456

5 months ago

11.0.0-rc.455

5 months ago

11.0.0-rc.452

6 months ago

11.0.0-rc.449

6 months ago

11.0.0-rc.446

6 months ago

11.0.0-rc.445

6 months ago

11.0.0-rc.444

6 months ago

11.0.0-rc.441

6 months ago

11.0.0-rc.439

6 months ago

11.0.0-rc.436

6 months ago

11.0.0-rc.435

6 months ago

11.0.0-rc.433

6 months ago

11.0.0-rc.432

6 months ago

11.0.0-rc.421

6 months ago

11.0.0-rc.419

6 months ago

11.0.0-rc.417

6 months ago

11.0.0-rc.413

6 months ago

11.0.0-rc.403

6 months ago

11.0.0-rc.402

6 months ago

11.0.0-rc.401

7 months ago

11.0.0-rc.396

7 months ago

11.0.0-rc.394

7 months ago

11.0.0-rc.390

7 months ago

11.0.0-rc.374

7 months ago

11.0.0-rc.373

7 months ago

11.0.0-rc.370

7 months ago

11.0.0-rc.369

7 months ago

11.0.0-rc.366

8 months ago

11.0.0-rc.364

8 months ago

11.0.0-rc.363

8 months ago

11.0.0-rc.362

8 months ago

11.0.0-rc.361

8 months ago

11.0.0-rc.359

8 months ago

11.0.0-rc.354

8 months ago

11.0.0-rc.351

8 months ago

11.0.0-rc.348

8 months ago

11.0.0-rc.347

8 months ago

11.0.0-rc.346

8 months ago

11.0.0-rc.345

8 months ago

11.0.0-rc.342

8 months ago

11.0.0-rc.340

8 months ago

11.0.0-rc.334

9 months ago

11.0.0-rc.332

9 months ago

11.0.0-rc.330

9 months ago

11.0.0-rc.329

9 months ago

11.0.0-next.326

9 months ago

11.0.0-next.325

9 months ago

11.0.0-next.327

9 months ago

11.0.0-next.322

9 months ago

11.0.0-next.324

9 months ago

11.0.0-next.323

9 months ago

11.0.0-next.320

9 months ago

10.45.2

10 months ago

10.45.2-canary.0

10 months ago

10.45.1

11 months ago

10.45.1-canary.24

11 months ago

10.45.1-canary.23

11 months ago

10.45.1-canary.20

12 months ago

10.45.1-canary.17

12 months ago

10.45.1-canary.16

12 months ago

10.45.1-canary.13

12 months ago

10.45.1-canary.11

12 months ago

10.45.1-canary.9

12 months ago

10.45.1-canary.8

12 months ago

10.45.0

12 months ago

10.45.1-canary.1

12 months ago

10.45.1-canary.0

12 months ago

10.45.1-canary.3

12 months ago

10.45.1-canary.2

12 months ago

10.45.1-canary.4

12 months ago

10.44.2-canary.34

12 months ago

10.44.2-canary.33

12 months ago

10.44.2-canary.37

12 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

1 year ago

10.43.4

1 year ago

10.43.7

1 year ago

10.43.6

1 year 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

1 year ago

10.44.1

1 year ago

10.33.1

1 year ago

10.33.0

1 year ago

10.30.0

2 years ago

10.32.0

2 years ago

10.31.0

2 years ago

10.28.0

2 years ago

10.26.0

2 years ago

10.24.0

2 years ago

10.28.1

2 years ago

10.28.2

2 years ago

10.27.0

2 years ago

10.27.1

2 years ago

10.25.0

2 years ago

10.25.1

2 years ago

10.23.1

2 years ago

10.29.0

2 years ago

10.27.2

2 years ago

10.29.1

2 years ago

10.27.3

2 years 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