mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
perf(mod queue): prevent re-renders from IPFS client state changes
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user