mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-23 00:03:33 +00:00
29 lines
631 B
TypeScript
29 lines
631 B
TypeScript
|
import { createContext, useContext } from "react";
|
||
|
|
||
|
const OnlineContext = createContext<{
|
||
|
online: boolean;
|
||
|
setOnline: (online: boolean) => void;
|
||
|
} | null>(null);
|
||
|
|
||
|
export function useIsOnline() {
|
||
|
const context = useContext(OnlineContext);
|
||
|
|
||
|
if (context === null) {
|
||
|
throw new Error("useIsOnline must be used within a OnlineProvider");
|
||
|
}
|
||
|
|
||
|
return context.online;
|
||
|
}
|
||
|
|
||
|
export function useSetOnline() {
|
||
|
const context = useContext(OnlineContext);
|
||
|
|
||
|
if (context === null) {
|
||
|
throw new Error("useSetOnline must be used within a OnlineProvider");
|
||
|
}
|
||
|
|
||
|
return context.setOnline;
|
||
|
}
|
||
|
|
||
|
export default OnlineContext.Provider;
|