mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-27 23:56:59 +00:00
- Introduced a new platform provider architecture to manage platform-specific functionalities. - Created `PlatformProvider`, `PlatformContext`, and related capabilities for handling downloads and key imports. - Integrated the platform provider into `AppRoot`, allowing for dynamic platform management. - Added error handling classes for unsupported and unimplemented methods. - Updated tests to validate the new platform provider functionalities and capabilities.
21 lines
781 B
TypeScript
21 lines
781 B
TypeScript
import { createContext, useContext, type PropsWithChildren } from 'react';
|
|
import type { PlatformProvider } from './PlatformProvider';
|
|
|
|
const PlatformReactContext = createContext<PlatformProvider | null>(null);
|
|
|
|
export function PlatformProviderHost({
|
|
provider,
|
|
children,
|
|
}: PropsWithChildren<{ provider: PlatformProvider }>): React.JSX.Element {
|
|
return <PlatformReactContext.Provider value={provider}>{children}</PlatformReactContext.Provider>;
|
|
}
|
|
|
|
// eslint-disable-next-line react-refresh/only-export-components -- hook colocated with context host
|
|
export function usePlatform(): PlatformProvider {
|
|
const provider = useContext(PlatformReactContext);
|
|
if (!provider) {
|
|
throw new Error('usePlatform() must be used within PlatformProviderHost');
|
|
}
|
|
return provider;
|
|
}
|