Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

useSessionList()

The useSessionList() hook returns an array of Session objects that have been registered on the client device.

useSessionList() returns

NameTypeDescription
isLoadedbooleanA boolean that is set to false until Clerk loads and initializes.
setActive()(params: SetActiveParams) => Promise<void>A function that sets the active session.
setSession() (deprecated)Deprecated in favor of setActive().
sessionsSession[]Holds an array of Session objects that have been registered on the client device.

SetActiveParams

NameTypeDescription
sessionSession | string | nullThe session resource or session ID (string version) to be set as active. If null, the current session is deleted.
organizationOrganization | string | nullThe organization resource or organization ID (string version) to be set as active in the current session. If null, the currently active organization is removed as active.
beforeEmit?(session?: Session | null) => void | Promise<any>Callback run just before the active session and/or organization is set to the passed object. Can be used to hook up for pre-navigation actions.

How to use the useSessionList() hook

The following example demonstrates how to use the useSessionList() hook to retrieve a list of sessions that have been registered on the client device. The isLoaded property is used to handle the loading state, and the sessions property is used to display the number of times the user has visited the page.

home.tsx
import { useSessionList } from "@clerk/clerk-react"; export default function Home() { const { isLoaded, sessions } = useSessionList(); if (!isLoaded) { // handle loading state return null; } return ( <div> <p>Welcome back. You have been here {sessions.length} times before. </p> </div> ) }

Last updated on February 22, 2024

What did you think of this content?

Clerk © 2024