@clerk/shared
Version:
Internal package utils used by the Clerk SDKs
67 lines • 1.66 kB
text/typescript
import { UseSessionListReturn } from "../../types/hooks.mjs";
//#region src/react/hooks/useSessionList.d.ts
/**
* The `useSessionList()` hook returns an array of [`Session`](https://clerk.com/docs/reference/objects/session) objects that have been registered on the client device.
*
* @unionReturnHeadings
* ["Initialization", "Loaded"]
*
* @function
*
* @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.
*
* <Tabs items='React,Next.js'>
* <Tab>
*
* ```tsx {{ filename: 'src/Home.tsx' }}
* import { useSessionList } from '@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>
* )
* }
* ```
*
* </Tab>
* <Tab>
*
* ```tsx {{ filename: '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>
* );
* }
* ```
*
* </Tab>
* </Tabs>
*/
declare const useSessionList: () => UseSessionListReturn;
//#endregion
export { useSessionList };