blob: c511aa4665d90818d8886c8dd4a55dbe6e3c009e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import React, { createContext, useContext, useState, useMemo } from 'react';
interface SessionContextType {
startTime: Date;
}
const SessionContext = createContext<SessionContextType | null>(null);
export const SessionProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const [startTime] = useState(new Date());
const value = useMemo(
() => ({
startTime,
}),
[startTime],
);
return (
<SessionContext.Provider value={value}>{children}</SessionContext.Provider>
);
};
export const useSession = () => {
const context = useContext(SessionContext);
if (!context) {
throw new Error('useSession must be used within a SessionProvider');
}
return context;
};
|