Skip to main content

4. Arguments for your loader

If you want the loader to take an argument, all you have to do is to add a queriesArg:

import { ConsumerProps } from "@ryfylke-react/rtk-query-loader";

// This means that any component that has props that extend this
// type can consume the loader using `withLoader`
type UserRouteLoaderProps = ConsumerProps<{
userId: string;

export const userRouteLoader = baseLoader.extend({
queriesArg: (props: UserRouteLoaderProps) => props.userId,
// type is now inferred from queriesArg return
useQueries: (userId) => {
const user = useGetUserQuery(userId);
const posts = useGetPostsByUser(userId);

return {
queries: {