Kaynağa Gözat

:bug: url 改变,ModeSwitch 没有变

visuddhinanda 2 yıl önce
ebeveyn
işleme
b999c00759

+ 8 - 5
dashboard/src/components/article/ModeSwitch.tsx

@@ -1,14 +1,17 @@
 import { Segmented } from "antd";
-import { useState } from "react";
+import { useEffect, useState } from "react";
 import { useIntl } from "react-intl";
 
 interface IWidget {
-  initMode?: string;
+  currMode?: string;
   onModeChange?: Function;
 }
-const ModeSwitchWidget = ({ initMode = "read", onModeChange }: IWidget) => {
+const ModeSwitchWidget = ({ currMode = "read", onModeChange }: IWidget) => {
   const intl = useIntl();
-  const [mode, setMode] = useState<string>(initMode);
+  const [mode, setMode] = useState<string>(currMode);
+  useEffect(() => {
+    setMode(currMode);
+  }, [currMode]);
   return (
     <Segmented
       size="middle"
@@ -17,7 +20,7 @@ const ModeSwitchWidget = ({ initMode = "read", onModeChange }: IWidget) => {
         backgroundColor: "rgb(129 129 129 / 17%)",
         display: "block",
       }}
-      defaultValue={initMode}
+      defaultValue={currMode}
       options={[
         {
           label: intl.formatMessage({ id: "buttons.read" }),

+ 1 - 1
dashboard/src/pages/library/article/show.tsx

@@ -79,7 +79,7 @@ const Widget = () => {
           <div></div>
           <div key="right" style={{ display: "flex" }}>
             <ModeSwitch
-              initMode={currMode}
+              currMode={currMode}
               onModeChange={(e: ArticleMode) => {
                 let output: any = { mode: e };
                 searchParams.forEach((value, key) => {