Skip to content

Commit

Permalink
Merge pull request IdoPesok#128 from IdoPesok/react-query-redirects
Browse files Browse the repository at this point in the history
handle redirects properly in react query
  • Loading branch information
IdoPesok authored Jun 17, 2024
2 parents c2ef4d4 + 4d0ea30 commit 5fd54c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-crabs-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"zsa-react-query": patch
---

Fixes redirect and not found usage
19 changes: 16 additions & 3 deletions packages/zsa-react-query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ export const setupServerActionHooks = <
...options,
queryFn: async ({ pageParam }) => {
const input = options.input({ pageParam: pageParam as TPageParam })
const [data, err] = await action(input)
const result = await action(input)

if (!result) return

const [data, err] = result

if (err) {
throw err
Expand Down Expand Up @@ -142,7 +146,11 @@ export const setupServerActionHooks = <
{
...options,
queryFn: async () => {
const [data, err] = await action(options.input)
const result = await action(options.input)

if (!result) return

const [data, err] = result

if (err) {
throw err
Expand Down Expand Up @@ -183,7 +191,12 @@ export const setupServerActionHooks = <
{
...options,
mutationFn: async (...args) => {
const [data, err] = await action(...args)
const result = await action(...args)

// redirect or not found
if (!result) return

const [data, err] = result

if (options?.returnError) {
return [data, err]
Expand Down

0 comments on commit 5fd54c2

Please sign in to comment.