Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

post request - useQuery #179

Unanswered
JoeGaffney asked this question in Q&A
Discussion options

Hey,

Is there a way to make post requests use useQuery I have some endpoints that I need to send a body to fetch data.

Is this possible allready or is there some other way to signify a useQuery should be made instead of a useMutation?

You must be logged in to vote

Replies: 1 comment

Comment options

I made a wrapper function that converts useMutation to useQuery, allowing all parameters to be passed in a type-safe way. I also wrote a tutorial for it:

Gist

Usage looks like this:

 const { data, isFetching } = useMutationQuery(
 useTableServicePaginatedWithFilters,
 {
 page: pagination?.pageIndex + 1,
 size: pagination?.pageSize,
 requestBody: { ...filter }
 }
 )

Open to any ideas for improvement—hope it helps!

Let me know if you’d like to turn this into a shareable npm package or add types for even better DX.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /