From aa29e185e4b39a3d0b18b2239434e4a6afaf553f Mon Sep 17 00:00:00 2001 From: GyDi Date: Mon, 20 Dec 2021 01:09:32 +0800 Subject: [PATCH] fix: mutate at the same time may be wrong --- src/pages/rules.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/rules.tsx b/src/pages/rules.tsx index 37b6b16..be63f42 100644 --- a/src/pages/rules.tsx +++ b/src/pages/rules.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useRef, useState } from "react"; import useSWR, { useSWRConfig } from "swr"; import { Box, Button, Grid, TextField, Typography } from "@mui/material"; import { @@ -28,13 +28,19 @@ const RulesPage = () => { .finally(() => setDisabled(false)); }; + const lockRef = useRef(false); const onProfileChange = (index: number) => { + if (lockRef.current) return; + lockRef.current = true; putProfiles(index) .then(() => { mutate("getProfiles", { ...profiles, current: index }, true); }) .catch((err) => { console.error(err); + }) + .finally(() => { + lockRef.current = false; }); };