mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix race condition
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import { useEffect } from "react";
|
||||
import { createAccount, setActiveAccount, useAccounts } from "@plebbit/plebbit-react-hooks";
|
||||
import useAnonModeStore from "./stores/useAnonModeStore";
|
||||
|
||||
const useAnonMode = (threadCid, execute) => {
|
||||
const {accounts} = useAccounts();
|
||||
const { anonymousMode } = useAnonModeStore();
|
||||
|
||||
useEffect(() => {
|
||||
const handleAnonMode = async () => {
|
||||
let storedAccounts = JSON.parse(localStorage.getItem('storedAccounts')) || {};
|
||||
|
||||
if (!anonymousMode) return;
|
||||
|
||||
if (!storedAccounts[threadCid] && execute) {
|
||||
await createAccount();
|
||||
const lastAccount = accounts[accounts.length - 1];
|
||||
@@ -21,7 +25,7 @@ const useAnonMode = (threadCid, execute) => {
|
||||
}
|
||||
|
||||
handleAnonMode();
|
||||
}, [threadCid, execute, accounts]);
|
||||
}, [threadCid, execute, accounts, anonymousMode]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user