Skip to content
Snippets Groups Projects
Commit aa29e185 authored by GyDi's avatar GyDi
Browse files

fix: mutate at the same time may be wrong

parent 8738fa3d
No related branches found
No related tags found
No related merge requests found
import { useState } from "react"; import { useRef, useState } from "react";
import useSWR, { useSWRConfig } from "swr"; import useSWR, { useSWRConfig } from "swr";
import { Box, Button, Grid, TextField, Typography } from "@mui/material"; import { Box, Button, Grid, TextField, Typography } from "@mui/material";
import { import {
...@@ -28,13 +28,19 @@ const RulesPage = () => { ...@@ -28,13 +28,19 @@ const RulesPage = () => {
.finally(() => setDisabled(false)); .finally(() => setDisabled(false));
}; };
const lockRef = useRef(false);
const onProfileChange = (index: number) => { const onProfileChange = (index: number) => {
if (lockRef.current) return;
lockRef.current = true;
putProfiles(index) putProfiles(index)
.then(() => { .then(() => {
mutate("getProfiles", { ...profiles, current: index }, true); mutate("getProfiles", { ...profiles, current: index }, true);
}) })
.catch((err) => { .catch((err) => {
console.error(err); console.error(err);
})
.finally(() => {
lockRef.current = false;
}); });
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment