i have and useEffect inside my component
useEffect(() => {
const interval = setInterval(() => {
setQueueState((pre) => {
return pre.map((line) => {
if (line.length === 0) return [];
line[0].items = line[0].items > 0 ? line[0].items - 1 : 0;
if (line[0].items > 0) {
return [
line[0],
...line.slice(1).filter((person) => person.items > 0)
];
} else {
return [...line.slice(1).filter((person) => person.items > 0)];
}
});
});
}, 4000);
return () => {
clearInterval(interval);
};
}, []);
What it basically does is to loop through an array of checkout lines and reduce the number of items of the first person in each line by 1. Now the problem with Strict Mode is that it gets reduced 2 times. I know it's because Strict Mode renders a component 2 times. I just want to know a way to avoid this and still use Strict Mode.