ソースを参照

fix: don't re-run global actions

Fela Maslen 4 年 前
コミット
a77966ea80
1 ファイル変更6 行追加1 行削除
  1. 6 1
      gmus-web/src/components/ui/cmus/wrapper.tsx

+ 6 - 1
gmus-web/src/components/ui/cmus/wrapper.tsx

@@ -42,8 +42,13 @@ export const CmusUIProvider: UIProviderComponent = ({
   const dispatch = useContext(DispatchContext);
   const [stateUI, dispatchUI] = useReducer(cmusUIReducer, initialCmusUIState, init, 'ui');
 
+  const globalActionSerialNumberPrev = useRef<number>(stateUI.globalActionSerialNumber);
   useEffect(() => {
-    if (stateUI.globalAction) {
+    if (
+      stateUI.globalAction &&
+      globalActionSerialNumberPrev.current !== stateUI.globalActionSerialNumber
+    ) {
+      globalActionSerialNumberPrev.current = stateUI.globalActionSerialNumber;
       dispatch(stateUI.globalAction);
     }
   }, [dispatch, stateUI.globalAction, stateUI.globalActionSerialNumber]);