1
0
Fork 0

Fix loadAcounts firing twice

This commit is contained in:
Lim Chee Aun 2023-10-29 11:47:20 +08:00
parent 25ff0d7835
commit 8180cc357e

View file

@ -1,6 +1,6 @@
import './generic-accounts.css';
import { useEffect, useState } from 'preact/hooks';
import { useEffect, useRef, useState } from 'preact/hooks';
import { InView } from 'react-intersection-observer';
import { useSnapshot } from 'valtio';
@ -56,15 +56,18 @@ export default function GenericAccounts({ onClose = () => {} }) {
})();
};
const firstLoad = useRef(true);
useEffect(() => {
if (staticAccounts?.length > 0) {
setAccounts(staticAccounts);
} else {
loadAccounts(true);
firstLoad.current = false;
}
}, [staticAccounts, fetchAccounts]);
useEffect(() => {
if (firstLoad.current) return;
// reloadGenericAccounts contains value like {id: 'mute', counter: 1}
// We only need to reload if the id matches
if (snapStates.reloadGenericAccounts?.id === id) {