10.45.2 • Published 7 days ago

@trpc/react-query v10.45.2

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

10 days ago

11.0.0-rc.698

10 days ago

11.0.0-rc.700

10 days ago

11.0.0-rc.695

12 days ago

11.0.0-rc.694

12 days ago

11.0.0-rc.693

12 days ago

11.0.0-rc.692

12 days ago

11.0.0-rc.688

15 days ago

11.0.0-rc.682

24 days ago

11.0.0-rc.678

24 days ago

11.0.0-rc.677

25 days ago

11.0.0-rc.666

1 month ago

11.0.0-rc.660

2 months ago

11.0.0-rc.659

2 months ago

11.0.0-rc.657

2 months ago

11.0.0-rc.648

2 months ago

11.0.0-rc.645

2 months ago

11.0.0-rc.643

2 months ago

11.0.0-rc.642

2 months ago

11.0.0-rc.638

2 months ago

11.0.0-rc.637

2 months ago

11.0.0-rc.633

2 months ago

11.0.0-rc.632

2 months ago

11.0.0-rc.630

2 months ago

11.0.0-rc.621

2 months ago

11.0.0-rc.619

3 months ago

11.0.0-rc.608

3 months ago

11.0.0-rc.607

3 months ago

11.0.0-rc.599

3 months ago

11.0.0-rc.604

3 months ago

11.0.0-rc.601

3 months ago

11.0.0-rc.593

3 months ago

11.0.0-rc.592

3 months ago

11.0.0-rc.591

3 months ago

11.0.0-rc.590

3 months ago

11.0.0-rc.589

3 months ago

11.0.0-rc.588

3 months ago

11.0.0-rc.587

3 months ago

11.0.0-rc.586

3 months ago

11.0.0-rc.584

3 months ago

11.0.0-rc.580

3 months ago

11.0.0-rc.577

3 months ago

11.0.0-rc.576

3 months ago

11.0.0-rc.571

3 months ago

11.0.0-rc.569

3 months ago

11.0.0-rc.567

3 months ago

11.0.0-rc.566

4 months ago

11.0.0-rc.565

4 months ago

11.0.0-rc.563

4 months ago

11.0.0-rc.561

4 months ago

11.0.0-rc.560

4 months ago

11.0.0-rc.553

4 months ago

11.0.0-rc.552

4 months ago

11.0.0-rc.551

4 months ago

11.0.0-rc.544

4 months ago

11.0.0-rc.532

4 months ago

11.0.0-rc.531

4 months ago

11.0.0-rc.530

4 months ago

11.0.0-rc.498

5 months ago

11.0.0-rc.490

5 months ago

11.0.0-rc.489

5 months ago

11.0.0-rc.487

5 months ago

11.0.0-rc.528

4 months ago

11.0.0-rc.524

4 months ago

11.0.0-rc.522

4 months ago

11.0.0-rc.521

4 months ago

11.0.0-rc.520

4 months ago

11.0.0-rc.502

5 months ago

11.0.0-rc.501

5 months ago

11.0.0-rc.500

5 months ago

11.0.0-rc.485

5 months ago

11.0.0-rc.482

5 months ago

11.0.0-rc.480

5 months ago

11.0.0-rc.383

8 months ago

11.0.0-rc.382

8 months ago

11.0.0-rc.377

8 months ago

11.0.0-rc.477

6 months ago

11.0.0-rc.475

6 months ago

11.0.0-rc.474

6 months ago

11.0.0-rc.467

6 months ago

11.0.0-rc.466

6 months ago

11.0.0-rc.465

6 months ago

11.0.0-rc.461

6 months ago

11.0.0-rc.460

6 months ago

11.0.0-rc.459

6 months ago

11.0.0-rc.458

6 months ago

11.0.0-rc.456

7 months ago

11.0.0-rc.455

7 months ago

11.0.0-rc.452

7 months ago

11.0.0-rc.449

7 months ago

11.0.0-rc.446

7 months ago

11.0.0-rc.445

7 months ago

11.0.0-rc.444

7 months ago

11.0.0-rc.441

7 months ago

11.0.0-rc.439

7 months ago

11.0.0-rc.436

7 months ago

11.0.0-rc.435

7 months ago

11.0.0-rc.433

7 months ago

11.0.0-rc.432

7 months ago

11.0.0-rc.421

7 months ago

11.0.0-rc.419

7 months ago

11.0.0-rc.417

7 months ago

11.0.0-rc.413

7 months ago

11.0.0-rc.403

7 months ago

11.0.0-rc.402

7 months ago

11.0.0-rc.401

8 months ago

11.0.0-rc.396

8 months ago

11.0.0-rc.394

8 months ago

11.0.0-rc.390

8 months ago

11.0.0-rc.374

8 months ago

11.0.0-rc.373

8 months ago

11.0.0-rc.370

8 months ago

11.0.0-rc.369

8 months ago

11.0.0-rc.366

9 months ago

11.0.0-rc.364

9 months ago

11.0.0-rc.363

9 months ago

11.0.0-rc.362

9 months ago

11.0.0-rc.361

9 months ago

11.0.0-rc.359

9 months ago

11.0.0-rc.354

9 months ago

11.0.0-rc.351

9 months ago

11.0.0-rc.348

9 months ago

11.0.0-rc.347

9 months ago

11.0.0-rc.346

9 months ago

11.0.0-rc.345

9 months ago

11.0.0-rc.342

9 months ago

11.0.0-rc.340

9 months ago

11.0.0-rc.334

10 months ago

11.0.0-rc.332

10 months ago

11.0.0-rc.330

10 months ago

11.0.0-rc.329

10 months ago

11.0.0-next.326

10 months ago

11.0.0-next.325

10 months ago

11.0.0-next.327

10 months ago

11.0.0-next.322

10 months ago

11.0.0-next.324

10 months ago

11.0.0-next.323

10 months ago

11.0.0-next.320

10 months ago

10.45.2

11 months ago

10.45.2-canary.0

11 months ago

10.45.1

12 months ago

10.45.1-canary.24

12 months ago

10.45.1-canary.23

12 months ago

10.45.0

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

2 years ago

10.34.0

2 years ago

10.35.0

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

2 years ago

10.33.0

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