minor fixes

This commit is contained in:
OrJDev
2022-09-27 12:08:35 +03:00
parent f54fcbf40a
commit f415f39c55
5 changed files with 21 additions and 13 deletions
+12 -4
View File
@@ -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<IAppRouter>();
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", {...}]))
```
+2 -2
View File
@@ -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",
+1 -1
View File
@@ -3,7 +3,7 @@
"description": "SolidJS tRPC",
"author": "OrJDev",
"license": "MIT",
"version": "0.0.3",
"version": "0.0.4",
"publishConfig": {
"access": "public"
},
+1 -1
View File
@@ -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",
+5 -5
View File
@@ -132,7 +132,7 @@ export function createSolidQueryHooks<TRouter extends AnyRouter>() {
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<TRouter extends AnyRouter>() {
>
): CreateInfiniteQueryResult<TQueryValues[TPath]["output"], TError> {
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)
);
},