Add user profile
Wrapper functions provided by the generated SDK can be used. For example, we can use these functions to access user profile data for the specific user id:
import { useRoqPlatformUserProfile } from '@/lib/roq'
const { data, isLoading } = useRoqPlatformUserProfile({
id: "8b249b07-bdd9-43f7-a10e-ace10f27ff66",
})
The useRoqPlatformUserProfile
hook utilizes ROQ platform method internally to retrieve the user profile data. This is the snippet code from the generated SDK:
lib/roq/roq-hooks.ts
export function useRoqPlatformUserProfile(
args?: UserProfileQueryVariables,
swrOptions?: SWRRequestOptions<UserProfileQuery>,
) {
const roq = useRoqClient();
const key = JSON.stringify(['useRoqPlatformUserProfile', args || {}]);
return useSWR<UserProfileQuery, Error>(
key,
async () => {
const result = await roq.roqPlatform.userProfile(args);
return result;
},
{
...swrOptions,
fallbackData: swrOptions?.initialData ?? swrOptions?.fallbackData,
},
);
}
The code in the highlighted line above is the one that calls the ROQ platform method.
const result = await roq.roqPlatform.userProfile(args);
Depending on your application needs, you can choose between using the hook or the ROQ client method.
Please note that the userProfile()
method is part of the ROQ platform API, hence any generated application will always have this API. You can read more about the userProfile()
API documentation here.