The useKeepSessionAlive hook provides functionality to extend the current user session without requiring re-authentication.

Import

import { useKeepSessionAlive } from "@getpara/react-sdk@alpha";

Usage

function SessionManager() {
  const { keepSessionAlive, keepSessionAliveAsync, isPending } = useKeepSessionAlive();
  const [lastRefresh, setLastRefresh] = useState<Date | null>(null);

  const handleKeepAlive = async () => {
    try {
      const success = await keepSessionAliveAsync();
      
      if (success) {
        setLastRefresh(new Date());
        console.log("Session extended successfully");
      }
    } catch (err) {
      console.error("Session extension error:", err);
    }
  };

  return (
    <button 
      onClick={handleKeepAlive}
      disabled={isPending}
    >
      {isPending ? "Extending..." : "Extend Session"}
    </button>
  );
}