Skip to main content
Docs

useSessionList()

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

Returns

There are multiple variants of this type available which you can select by clicking on one of the tabs.

  • Name
    isLoaded
    Type
    false
    Description

    A boolean that indicates whether Clerk has completed initialization. Initially false, becomes true once Clerk loads.

  • Name
    sessions
    Type
    undefined
    Description

    A list of sessions that have been registered on the client device.

  • Name
    setActive
    Type
    undefined
    Description

    A function that sets the active session and/or organization. See the .

  • Name
    isLoaded
    Type
    true
    Description

    A boolean that indicates whether Clerk has completed initialization. Initially false, becomes true once Clerk loads.

  • Name
    sessions
    Type
    []
    Description

    A list of sessions that have been registered on the client device.

  • Name
    setActive()
    Type
    (setActiveParams: SetActiveParams) => Promise<void>
    Description

    A function that sets the active session and/or organization. See the .

Example

Get a list of sessions

The following example uses useSessionList() to get a list of sessions that have been registered on the client device. The sessions property is used to show the number of times the user has visited the page.

src/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've been here {sessions.length} times before.</p>
    </div>
  );
}
app/page.tsx
"use client";

import { useSessionList } from "@clerk/nextjs";

export default function HomePage() {
  const { isLoaded, sessions } = useSessionList();

  if (!isLoaded) {
    // Handle loading state
    return null;
  }

  return (
    <div>
      <p>Welcome back. You've been here {sessions.length} times before.</p>
    </div>
  );
}

Feedback

What did you think of this content?

Last updated on