Refactor components to remove forwardRef and simplify props handling

- Updated multiple components to remove the use of forwardRef, simplifying the props structure.
- Adjusted imports and component definitions accordingly.
- Ensured consistent handling of refs and props across various viewer components.
- Improved readability and maintainability of the codebase.
This commit is contained in:
Tunglies
2025-09-30 14:23:29 +08:00
parent 0c88568cd7
commit 1cd013fb94
25 changed files with 1380 additions and 1455 deletions

View File

@@ -1,11 +1,5 @@
import { listen } from "@tauri-apps/api/event";
import React, {
createContext,
useContext,
useEffect,
useMemo,
useRef,
} from "react";
import React, { createContext, use, useEffect, useMemo, useRef } from "react";
import useSWR from "swr";
import { useClashInfo } from "@/hooks/use-clash";
@@ -589,14 +583,12 @@ export const AppDataProvider = ({
refreshAll,
]);
return (
<AppDataContext.Provider value={value}>{children}</AppDataContext.Provider>
);
return <AppDataContext value={value}>{children}</AppDataContext>;
};
// 自定义Hook访问全局数据
export const useAppData = () => {
const context = useContext(AppDataContext);
const context = use(AppDataContext);
if (!context) {
throw new Error("useAppData必须在AppDataProvider内使用");

View File

@@ -1,4 +1,4 @@
import React, { createContext, useCallback, useContext, useState } from "react";
import React, { createContext, useCallback, use, useState } from "react";
interface ChainProxyContextType {
isChainMode: boolean;
@@ -26,7 +26,7 @@ export const ChainProxyProvider = ({
}, []);
return (
<ChainProxyContext.Provider
<ChainProxyContext
value={{
isChainMode,
setChainMode,
@@ -35,12 +35,12 @@ export const ChainProxyProvider = ({
}}
>
{children}
</ChainProxyContext.Provider>
</ChainProxyContext>
);
};
export const useChainProxy = () => {
const context = useContext(ChainProxyContext);
const context = use(ChainProxyContext);
if (!context) {
throw new Error("useChainProxy must be used within a ChainProxyProvider");
}