Next.js
Add User Profile

Add user profile

Wrapper functions provided by the generated SDK can be used instead of calling useRoqClient() directly. 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",
	withProviders: true
})

The useRoqPlatformUserProfile hook utilizes the useRoqClient() method internally to retrieve 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,
    },
  );
}

Depending on your application needs, you can choose between using the hook or the useRoqClient() method.

Please note that the userProfile() method is part of the ROQ platform API and cannot be generated. However, you can still update user profile data in the ROQ Console. You can read the documentation of the userProfile() API here.