From f415f39c55116013ddb94a8d9a79da4a2199d499 Mon Sep 17 00:00:00 2001 From: OrJDev Date: Tue, 27 Sep 2022 12:08:35 +0300 Subject: [PATCH] minor fixes --- README.MD | 16 ++++++++++++---- package-lock.json | 4 ++-- package.json | 2 +- rollup.config.js | 2 +- src/{index.tsx => index.ts} | 10 +++++----- 5 files changed, 21 insertions(+), 13 deletions(-) rename src/{index.tsx => index.ts} (95%) diff --git a/README.MD b/README.MD index 595057a..4357fe1 100644 --- a/README.MD +++ b/README.MD @@ -14,8 +14,8 @@ npm install solid-trpc @tanstack/solid-query ```ts // utils/trpc.ts -import { IAppRouter } from "api/src/routers/_route"; // your trpc appRouter type import { createSolidQueryHooks } from "solid-trpc"; +import { IAppRouter } from "api/src/routers/_route"; // your trpc appRouter type export const trpc = createSolidQueryHooks(); export const client = trpc.createClient({ @@ -52,7 +52,7 @@ export default App; ```tsx // pages/Home.tsx import { Component } from "solid-js"; -import { trpc } from "../../utils/trpc"; +import { trpc } from "../utils/trpc"; interface IHomeProps {} @@ -74,7 +74,7 @@ export default Home; ```tsx // pages/Home.tsx import { Component, onMount } from "solid-js"; -import { trpc } from "../../utils/trpc"; +import { trpc } from "../utils/trpc"; interface IHomeProps {} @@ -99,4 +99,12 @@ export default Home; - No SSR - 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", {...}])) +``` diff --git a/package-lock.json b/package-lock.json index 56a1dcd..85406c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "solid-trpc", - "version": "0.0.3", + "version": "0.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "solid-trpc", - "version": "0.0.3", + "version": "0.0.4", "license": "MIT", "devDependencies": { "@babel/core": "^7.18.13", diff --git a/package.json b/package.json index a1f2fd7..f16fe3d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "SolidJS tRPC", "author": "OrJDev", "license": "MIT", - "version": "0.0.3", + "version": "0.0.4", "publishConfig": { "access": "public" }, diff --git a/rollup.config.js b/rollup.config.js index ce2a2af..a5bce94 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,7 +2,7 @@ import babel from "@rollup/plugin-babel"; import nodeResolve from "@rollup/plugin-node-resolve"; export default { - input: "src/index.tsx", + input: "src/index.ts", output: [ { file: "dist/index.js", diff --git a/src/index.tsx b/src/index.ts similarity index 95% rename from src/index.tsx rename to src/index.ts index 2b02e5b..a728764 100644 --- a/src/index.tsx +++ b/src/index.ts @@ -132,7 +132,7 @@ export function createSolidQueryHooks() { opts?.enabled !== false && !ctx.queryClient.getQueryCache().find(pathAndInput()) ) { - ctx.prefetchQuery(pathAndInput as any, opts as any); + ctx.prefetchQuery(pathAndInput(), opts as any); } return __createQuery(pathAndInput, () => @@ -178,21 +178,21 @@ export function createSolidQueryHooks() { > ): CreateInfiniteQueryResult { const [path, input] = pathAndInput(); - const { client, prefetchInfiniteQuery, queryClient } = useContext(); + const ctx = useContext(); if ( typeof window === "undefined" && 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( pathAndInput as any, ({ pageParam }) => { const actualInput = { ...((input as any) ?? {}), cursor: pageParam }; - return (client as any).query( + return (ctx.client as any).query( ...getClientArgs([path, actualInput], opts) ); },