-
export const userQuery = () => ({
queryKey: ['user'],
queryFn: async () => getUser(),
});
export async function userLoader(qc:QueryClient) {
return (
qc.getQueryData(userQuery().queryKey)
?? (await qc.fetchQuery(userQuery()))
);
} I'm using this query in my loader and the loader in this nested route: <Route
path="settings"
element={<Settings />}
loader={userLoader(qc)}
> The issue, however, is that userLoader returns a |
Beta Was this translation helpful? Give feedback.
Answered by
arthtyagi
Sep 15, 2022
Replies: 1 comment
-
Fixed it by changing the return type to export function userLoader(qc: QueryClient) {
return async () => {
const data = qc.getQueryData(userQuery().queryKey);
if (data) return data;
return qc.fetchQuery(userQuery());
};
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
arthtyagi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed it by changing the return type to
() => Promise<{} | null>
.