The useOrganizationList() hook provides access to the current user's Organization memberships, invitations, and suggestions. It also includes methods for creating new Organizations and managing the Active Organization.
By default, the userMemberships, userInvitations, and userSuggestions attributes are not populated. To fetch and paginate the data, you must pass true or an object with the desired properties.
Optional properties that are shared across the userMemberships, userInvitations, and userSuggestions properties.
Name
initialPage?
Type
number
Description
A number that specifies which page to fetch. For example, if initialPage is set to 10, it will skip the first 9 pages and fetch the 10th page. Defaults to 1.
Name
pageSize?
Type
number
Description
A number that specifies the maximum number of results to return per page. Defaults to 10.
Name
infinite?
Type
boolean
Description
If true, newly fetched data will be appended to the existing list rather than replacing it. Useful for implementing infinite scroll functionality. Defaults to false.
Name
keepPreviousData?
Type
boolean
Description
If true, the previous data will be kept in the cache until new data is fetched. Defaults to false.
A function that returns a Promise which resolves to the newly created Organization.
Name
isLoaded
Type
boolean
Description
A boolean that indicates whether Clerk has completed initialization and there is an authenticated user. Initially false, becomes true once Clerk loads with a user.
An array that contains the fetched data. For example, for the memberships attribute, data will be an array of OrganizationMembershipJavaScript Icon objects.
Name
error
Type
null | ClerkAPIResponseError
Description
Clerk's API response error object.
Name
fetchNext
Type
() => void
Description
A function that triggers the next page to be loaded. This is the same as fetchPage(page => Math.min(pageCount, page + 1)).
Name
fetchPage
Type
ValueOrSetter<number>
Description
A function that triggers a specific page to be loaded.
Name
fetchPrevious
Type
() => void
Description
A function that triggers the previous page to be loaded. This is the same as fetchPage(page => Math.max(0, page - 1)).
Name
hasNextPage
Type
boolean
Description
A boolean that indicates if there are available pages to be fetched.
Name
hasPreviousPage
Type
boolean
Description
A boolean that indicates if there are available pages to be fetched.
Name
isError
Type
boolean
Description
A boolean that indicates the request failed.
Name
isFetching
Type
boolean
Description
A boolean that is true if there is an ongoing request or a revalidation.
Name
isLoading
Type
boolean
Description
A boolean that is true if there is an ongoing request and there is no fetched data.
Name
page
Type
number
Description
The current page.
Name
pageCount
Type
number
Description
The total amount of pages. It is calculated based on count, initialPage, and pageSize.
Name
revalidate
Type
() => Promise<void>
Description
A function that triggers a revalidation of the current page.
To keep network usage to a minimum, developers are required to opt-in by specifying which resource they need to fetch and paginate through. So by default, the userMemberships, userInvitations, and userSuggestions attributes are not populated. You must pass true or an object with the desired properties to fetch and paginate the data.
// userMemberships.data will never be populatedconst { userMemberships } =useOrganizationList()// Use default values to fetch userMemberships, such as initialPage = 1 and pageSize = 10const { userMemberships } =useOrganizationList({ userMemberships:true,})// Pass your own values to fetch userMembershipsconst { userMemberships } =useOrganizationList({ userMemberships: { pageSize:20, initialPage:2,// skips the first page },})// Aggregate pages in order to render an infinite listconst { userMemberships } =useOrganizationList({ userMemberships: { infinite:true, },})
The following example demonstrates how to use the infinite property to fetch and append new data to the existing list. The userMemberships attribute will be populated with the first page of the user's Organization memberships. When the "Load more" button is clicked, the fetchNext helper function will be called to append the next page of memberships to the list.
The following example demonstrates how to use the fetchPrevious and fetchNext helper functions to paginate through the data. The userInvitations attribute will be populated with the first page of invitations. When the "Previous page" or "Next page" button is clicked, the fetchPrevious or fetchNext helper function will be called to fetch the previous or next page of invitations.
Notice the difference between this example's pagination and the infinite pagination example above.