mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-24 22:52:15 +08:00
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
49 lines
1.2 KiB
TypeScript
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;
|
|
};
|