Skip to main content

useWellPlayed

The useWellPlayed hook provides access to the WellPlayed context, including the organization ID, GraphQL API client, typed client, and the current access token.

Returns

organizationId
string
The organization ID configured in the WellPlayedProvider.
apiClient
ApolloClient<NormalizedCacheObject>
The Apollo GraphQL client configured for the WellPlayed API. Use this for making GraphQL queries and mutations.
typedClient
ReturnType<typeof createTypedClient>
The typed client for making type-safe API requests to the WellPlayed API.
accessToken
string | undefined
The current OIDC access token, if the user is authenticated. Returns undefined if not authenticated.

Usage Example

import { useWellPlayed } from '@wellplayed.gg/react-sdk';

const MyComponent = () => {
  const { organizationId, apiClient, typedClient, accessToken } = useWellPlayed();
  
  console.log('Organization ID:', organizationId);
  console.log('Is authenticated:', !!accessToken);
  
  // Use the clients to interact with the WellPlayed API
  // ...
  
  return <div>My Component</div>;
};

Error Handling

This hook will throw an error if used outside of a WellPlayedProvider:
Error: useWellPlayed must be used within a WellPlayedProvider
Make sure your component is wrapped with WellPlayedProvider before using this hook.

Type Definition

const useWellPlayed: () => {
  organizationId: string;
  apiClient: ApolloClient<NormalizedCacheObject>;
  typedClient: ReturnType<typeof createTypedClient>;
  accessToken?: string;
}

Build docs developers (and LLMs) love