Buckets:
| import { useSyncExternalStore } from 'react'; | |
| import type { | |
| SetGlobalsEvent} from './types'; | |
| import { | |
| SET_GLOBALS_EVENT_TYPE, | |
| type OpenAiGlobals, | |
| } from './types'; | |
| export function useOpenAiGlobal<K extends keyof OpenAiGlobals>( | |
| key: K | |
| ): OpenAiGlobals[K] | null { | |
| return useSyncExternalStore( | |
| (onChange) => { | |
| if (typeof window === 'undefined') { | |
| return () => {}; | |
| } | |
| const handleSetGlobal = (event: SetGlobalsEvent) => { | |
| const value = event.detail.globals[key]; | |
| if (value === undefined) { | |
| return; | |
| } | |
| onChange(); | |
| }; | |
| window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, { | |
| passive: true, | |
| }); | |
| return () => { | |
| window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal); | |
| }; | |
| }, | |
| () => window.openai?.[key] ?? null, | |
| () => window.openai?.[key] ?? null | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 840 Bytes
- Xet hash:
- e5a1612f35d1aec3a64183fb635993c3c5394e40f236cc15e9739611d1a09329
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.