2025-05-24 00:44:17 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React, { createContext } from 'react';
|
|
|
|
|
import { StreamingState } from '../types.js';
|
|
|
|
|
|
2025-05-28 19:46:08 +00:00
|
|
|
export const StreamingContext = createContext<StreamingState | undefined>(
|
2025-05-24 00:44:17 -07:00
|
|
|
undefined,
|
|
|
|
|
);
|
|
|
|
|
|
2025-05-28 19:46:08 +00:00
|
|
|
export const useStreamingContext = (): StreamingState => {
|
2025-05-24 00:44:17 -07:00
|
|
|
const context = React.useContext(StreamingContext);
|
|
|
|
|
if (context === undefined) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'useStreamingContext must be used within a StreamingContextProvider',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return context;
|
|
|
|
|
};
|