perf(mod queue): prevent re-renders from IPFS client state changes

This commit is contained in:
plebeius
2026-01-11 15:39:46 +01:00
parent ab353b59f6
commit 33943c3de9
2 changed files with 57 additions and 31 deletions
@@ -1,15 +1,22 @@
import { useAccountSubplebbits } from '@plebbit/plebbit-react-hooks';
import { useMemo } from 'react';
import useAccountsStore from '@plebbit/plebbit-react-hooks/dist/stores/accounts';
import { MultisubSubplebbit } from './use-default-subplebbits';
export const useAccountSubplebbitsWithMetadata = (): MultisubSubplebbit[] => {
const { accountSubplebbits } = useAccountSubplebbits();
const subplebbitsWithMetadata = useAccountsStore(
(state) => {
const activeAccountId = state.activeAccountId;
const activeAccount = activeAccountId ? state.accounts[activeAccountId] : undefined;
const accountSubplebbits = activeAccount?.subplebbits || {};
return Object.entries(accountSubplebbits).map(([address, sub]) => ({
address,
title: (sub as any).title,
}));
},
(prev, next) => {
if (prev.length !== next.length) return false;
return prev.every((item, idx) => item.address === next[idx].address && item.title === next[idx].title);
},
);
return useMemo(() => {
return Object.entries(accountSubplebbits || {}).map(([address, sub]) => ({
address,
title: (sub as any).title,
// We can map other fields if needed
}));
}, [accountSubplebbits]);
return subplebbitsWithMetadata;
};