minor fixes
This commit is contained in:
@@ -14,8 +14,8 @@ npm install solid-trpc @tanstack/solid-query
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
// utils/trpc.ts
|
// utils/trpc.ts
|
||||||
import { IAppRouter } from "api/src/routers/_route"; // your trpc appRouter type
|
|
||||||
import { createSolidQueryHooks } from "solid-trpc";
|
import { createSolidQueryHooks } from "solid-trpc";
|
||||||
|
import { IAppRouter } from "api/src/routers/_route"; // your trpc appRouter type
|
||||||
|
|
||||||
export const trpc = createSolidQueryHooks<IAppRouter>();
|
export const trpc = createSolidQueryHooks<IAppRouter>();
|
||||||
export const client = trpc.createClient({
|
export const client = trpc.createClient({
|
||||||
@@ -52,7 +52,7 @@ export default App;
|
|||||||
```tsx
|
```tsx
|
||||||
// pages/Home.tsx
|
// pages/Home.tsx
|
||||||
import { Component } from "solid-js";
|
import { Component } from "solid-js";
|
||||||
import { trpc } from "../../utils/trpc";
|
import { trpc } from "../utils/trpc";
|
||||||
|
|
||||||
interface IHomeProps {}
|
interface IHomeProps {}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ export default Home;
|
|||||||
```tsx
|
```tsx
|
||||||
// pages/Home.tsx
|
// pages/Home.tsx
|
||||||
import { Component, onMount } from "solid-js";
|
import { Component, onMount } from "solid-js";
|
||||||
import { trpc } from "../../utils/trpc";
|
import { trpc } from "../utils/trpc";
|
||||||
|
|
||||||
interface IHomeProps {}
|
interface IHomeProps {}
|
||||||
|
|
||||||
@@ -99,4 +99,12 @@ export default Home;
|
|||||||
|
|
||||||
- No SSR
|
- No SSR
|
||||||
- Replace "use" with "create" (e.g. useQuery -> createQuery)
|
- Replace "use" with "create" (e.g. useQuery -> createQuery)
|
||||||
- Query paths (key and input) are being treated as Solid Accessor (callback) instead of a string (eg: useQuery(["MyKey", {...}]) -> createQuery(()=> ["MyKey", {...}]))
|
- Query paths (key and input) are being treated as Solid Accessor (callback):
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// instead of a string:
|
||||||
|
useQuery(["MyKey", {...}]
|
||||||
|
|
||||||
|
// it becomes a callback:
|
||||||
|
createQuery(()=> ["MyKey", {...}]))
|
||||||
|
```
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "solid-trpc",
|
"name": "solid-trpc",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "solid-trpc",
|
"name": "solid-trpc",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.18.13",
|
"@babel/core": "^7.18.13",
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
"description": "SolidJS tRPC",
|
"description": "SolidJS tRPC",
|
||||||
"author": "OrJDev",
|
"author": "OrJDev",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import babel from "@rollup/plugin-babel";
|
|||||||
import nodeResolve from "@rollup/plugin-node-resolve";
|
import nodeResolve from "@rollup/plugin-node-resolve";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: "src/index.tsx",
|
input: "src/index.ts",
|
||||||
output: [
|
output: [
|
||||||
{
|
{
|
||||||
file: "dist/index.js",
|
file: "dist/index.js",
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ export function createSolidQueryHooks<TRouter extends AnyRouter>() {
|
|||||||
opts?.enabled !== false &&
|
opts?.enabled !== false &&
|
||||||
!ctx.queryClient.getQueryCache().find(pathAndInput())
|
!ctx.queryClient.getQueryCache().find(pathAndInput())
|
||||||
) {
|
) {
|
||||||
ctx.prefetchQuery(pathAndInput as any, opts as any);
|
ctx.prefetchQuery(pathAndInput(), opts as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
return __createQuery(pathAndInput, () =>
|
return __createQuery(pathAndInput, () =>
|
||||||
@@ -178,21 +178,21 @@ export function createSolidQueryHooks<TRouter extends AnyRouter>() {
|
|||||||
>
|
>
|
||||||
): CreateInfiniteQueryResult<TQueryValues[TPath]["output"], TError> {
|
): CreateInfiniteQueryResult<TQueryValues[TPath]["output"], TError> {
|
||||||
const [path, input] = pathAndInput();
|
const [path, input] = pathAndInput();
|
||||||
const { client, prefetchInfiniteQuery, queryClient } = useContext();
|
const ctx = useContext();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof window === "undefined" &&
|
typeof window === "undefined" &&
|
||||||
opts?.enabled !== false &&
|
opts?.enabled !== false &&
|
||||||
!queryClient.getQueryCache().find(pathAndInput())
|
!ctx.queryClient.getQueryCache().find(pathAndInput())
|
||||||
) {
|
) {
|
||||||
prefetchInfiniteQuery(pathAndInput as any, opts as any);
|
ctx.prefetchInfiniteQuery(pathAndInput() as any, opts as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
return __createInfiniteQuery(
|
return __createInfiniteQuery(
|
||||||
pathAndInput as any,
|
pathAndInput as any,
|
||||||
({ pageParam }) => {
|
({ pageParam }) => {
|
||||||
const actualInput = { ...((input as any) ?? {}), cursor: pageParam };
|
const actualInput = { ...((input as any) ?? {}), cursor: pageParam };
|
||||||
return (client as any).query(
|
return (ctx.client as any).query(
|
||||||
...getClientArgs([path, actualInput], opts)
|
...getClientArgs([path, actualInput], opts)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Reference in New Issue
Block a user