add
This commit is contained in:
parent
9b4818f2ac
commit
845b08d7db
|
@ -1,5 +1,46 @@
|
||||||
export default async function Home() {
|
'use client';
|
||||||
return <div>
|
|
||||||
|
|
||||||
</div>;
|
import { api } from '@repo/client';
|
||||||
|
import { Button } from '@repo/ui/components/button';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
import { httpBatchLink } from '@trpc/client';
|
||||||
|
|
||||||
|
function HomeContent() {
|
||||||
|
const [name, setName] = useState('');
|
||||||
|
const helloQuery = api.hello.useQuery(name || undefined);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-4">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
placeholder="输入名字"
|
||||||
|
className="border p-2 mr-2"
|
||||||
|
/>
|
||||||
|
<Button onClick={() => helloQuery.refetch()}>{helloQuery.isLoading ? '加载中...' : helloQuery.data}</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
const [queryClient] = useState(() => new QueryClient());
|
||||||
|
const [trpcClient] = useState(() =>
|
||||||
|
api.createClient({
|
||||||
|
links: [
|
||||||
|
httpBatchLink({
|
||||||
|
url: 'http://localhost:3000/api/trpc',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<api.Provider client={trpcClient} queryClient={queryClient}>
|
||||||
|
<HomeContent />
|
||||||
|
</api.Provider>
|
||||||
|
</QueryClientProvider>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
export * from './useEntity';
|
||||||
export * from "./useEntity"
|
export * from './useHello';
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { api } from '../trpc';
|
||||||
|
|
||||||
|
export function useHello() {
|
||||||
|
return {
|
||||||
|
hello: api.hello,
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import { AppRouter } from "@repo/backend/trpc"
|
import { AppRouter } from '@repo/backend/trpc';
|
||||||
import { inferReactQueryProcedureOptions } from "@trpc/react-query";
|
import { inferReactQueryProcedureOptions } from '@trpc/react-query';
|
||||||
import { inferRouterInputs, inferRouterOutputs } from "@trpc/server";
|
import { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
||||||
import { createTRPCContext } from '@trpc/tanstack-react-query';
|
import { createTRPCContext } from '@trpc/tanstack-react-query';
|
||||||
export type ReactQueryOptions = inferReactQueryProcedureOptions<AppRouter>;
|
export type ReactQueryOptions = inferReactQueryProcedureOptions<AppRouter>;
|
||||||
export type RouterInputs = inferRouterInputs<AppRouter>;
|
export type RouterInputs = inferRouterInputs<AppRouter>;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
export * from "./api"
|
export * from './api';
|
||||||
|
|
Loading…
Reference in New Issue