Files
clash-verge-rev/src/providers/chain-proxy-provider.tsx
T
Tunglies d9a5c11d6a refactor: improve code readability and consistency in proxy-chain and uri-parser utilities
refactor: add keys to icons in routers for improved rendering and performance
refactor: optimize RegExp polyfill by using Object.prototype.hasOwnProperty.call
refactor: reorder imports in chain-proxy-provider for consistency
refactor: remove unused "obfs-opts" property from IProxySnellConfig interface

refactor: reorganize imports and enhance refresh logic in app data provider

refactor: re-enable prop-types linting for better type safety in BaseDialog component

refactor: update dependencies in effect hooks for improved stability and performance
2025-09-20 11:19:36 +08:00

49 lines
1.2 KiB
TypeScript

import React, { createContext, useCallback, useContext, useState } from "react";
interface ChainProxyContextType {
isChainMode: boolean;
setChainMode: (isChain: boolean) => void;
chainConfigData: string | null;
setChainConfigData: (data: string | null) => void;
}
const ChainProxyContext = createContext<ChainProxyContextType | null>(null);
export const ChainProxyProvider = ({
children,
}: {
children: React.ReactNode;
}) => {
const [isChainMode, setIsChainMode] = useState(false);
const [chainConfigData, setChainConfigData] = useState<string | null>(null);
const setChainMode = useCallback((isChain: boolean) => {
setIsChainMode(isChain);
}, []);
const setChainConfigDataCallback = useCallback((data: string | null) => {
setChainConfigData(data);
}, []);
return (
<ChainProxyContext.Provider
value={{
isChainMode,
setChainMode,
chainConfigData,
setChainConfigData: setChainConfigDataCallback,
}}
>
{children}
</ChainProxyContext.Provider>
);
};
export const useChainProxy = () => {
const context = useContext(ChainProxyContext);
if (!context) {
throw new Error("useChainProxy must be used within a ChainProxyProvider");
}
return context;
};