I need a urgent help with this #4293
Unanswered
Jassi10000-zz
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Not sure what you mean with this, looks like you are doing GET-requests, which should only need queries. Mutation are meant for PUT/POST/PATCH-requests, where you change data. Note, I haven't tested anything and there can be typos - but it should get you started: const { data: archivedProjects, isSuccess } = useQuery(
['archivedProjects'],
projectsApi.getArchivedProjects
)
const projectQueries = archivedProjects?.map((projectId) => ({
queryKey: ['project', projectId],
queryFn: () => projectsApi.get(projectId),
select: (data) => ({
project_name: data.name,
dueDate: data.dueDate,
createdAt: data.createdAt,
status: data.status,
}),
}))
const totalProjects = archivedProjects?.length
const projectResults = useQueries({ queries: projectQueries })
const allSuccess = projectResults.every(({ isSuccess }) => isSuccess)
const firstError = !allSuccess && projectResults.find({ error }) => error)
const project = allSuccess ? projectResults.map(query => project.data) : null |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I want to convert this using React Query
I have learnt useMutation , but only one API call being made , also we can't access the response that we get from the API call
Can somene help me with this ?
Beta Was this translation helpful? Give feedback.
All reactions