Comments (3)
I have figured out. The useQuery
's queryFn
needs to be on the server side.
actions.ts:
"use server";
export const fetchSettings = async () => {
const { data } = await client.GET("/api/settings/config-properties");
return data;
};
My client component:
"use client";
import { fetchSettings } from "@/lib/actions";
import { useQuery } from "@tanstack/react-query";
const { isPending, error, data, isFetching } = useQuery({
queryKey: ["getConfigProperties"],
queryFn: async () => fetchSettings(),
});
I don't know why needed like this in my case, but maybe worth a note somewhere in the docs.
Hope it helps someone.
from openapi-typescript.
@borzaka Thatβs a good find! Maybe this would be a good addition to examples/next
(since the React Query example is currently only client-side)? Or even a new examples/next-react-query
would be great as well if youβre able to provide it
from openapi-typescript.
- The Next.js example is on the server side, so no problem there with openapi-typescript alone without React Query.
- The React Query example is on the client side, but I have no idea why works there.
Every other example I found with Next.js and React Query, the queryFn
was on the server side. Like in this:
https://github.com/developedbyed/next14-query-combo-cache-destroyer/tree/master
app/page.tsx
import PostForm from "@/components/post-form"
import Posts from "@/components/posts"
import { fetchPosts } from "@/server/actions/create-post"
import {
QueryClient,
HydrationBoundary,
dehydrate,
} from "@tanstack/react-query"
export default async function Home() {
const queryClient = new QueryClient()
await queryClient.prefetchQuery({
queryKey: ["posts"],
queryFn: fetchPosts,
})
return (
<main>
<HydrationBoundary state={dehydrate(queryClient)}>
<PostForm />
<Posts />
</HydrationBoundary>
</main>
)
}
server/actions/create-post.ts
"use server";
export const fetchPosts = async () => {
const posts = await db.query.posts.findMany({
with: {
author: true,
likes: true,
},
orderBy: (posts, { desc }) => [desc(posts.timestamp)],
})
if (!posts) return { error: "No posts π" }
if (posts) return { success: posts }
}
And I also have problem to create type interface, to pass down props to the server side.
from openapi-typescript.
Related Issues (20)
- Transform only transforms referenced schemas HOT 1
- Hoping to wrap the client for single arg calls
- Metadata generation
- Allow client option for custom dispatcher into fetch requests (e.g. to disable certificate validation) HOT 6
- advice on how to connect a frontend (swagger?) while using this lib
- Set baseUrl per request
- 0.9.4 breaks some Typescript configurations HOT 3
- Response types from openapi-fetch ignore null values
- Multiple security schemes not supported
- `--properties-required-by-default` and `--default-non-nullable` flags do not work HOT 1
- Nested object's properties are mapped to unknown, but in OpenAPI they are typed correctly HOT 3
- "AdditionalProperties" reflects onto existing properties and causes TypeScript compile errors HOT 1
- Issues with references (`$ref`) resolution HOT 2
- Error with negative numbers in enums HOT 2
- Allow for custom types in path params serialization (and maybe other places serialization too)
- Types derived for oneOf construct result in TS2502 error HOT 4
- Uncaught error when body is `undefined` in request init HOT 6
- 'path' does not exist in type '{ query?: Record<string, unknown> | undefined; }' HOT 4
- issue on - generate client when yaml has mutiple same external ref
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-typescript.