Skip to content

Commit

Permalink
Merge pull request #1374 from decent-dao/dc/request-relief-01
Browse files Browse the repository at this point in the history
Fix Multiple Re-render caused by `useEffect`
  • Loading branch information
adamgall authored Feb 26, 2024
2 parents 78c934a + fa6be79 commit 236b8c3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/pages/DaoHierarchy/DaoNode.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box } from '@chakra-ui/react';
import { utils } from 'ethers';
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useLoadDAONode } from '../../../hooks/DAO/loaders/useLoadDAONode';
import { useLoadDAOData } from '../../../hooks/DAO/useDAOData';
import { useFractal } from '../../../providers/App/AppProvider';
Expand All @@ -26,6 +26,7 @@ export function DaoNode({
daoAddress?: string;
depth: number;
}) {
const onMountOnly = useRef(true);
const [fractalNode, setNode] = useState<FractalNode>();
const { loadDao } = useLoadDAONode();
const { daoData } = useLoadDAOData(fractalNode, parentAddress);
Expand All @@ -38,7 +39,7 @@ export function DaoNode({
const isCurrentDAO = daoAddress === currentDAOAddress;

useEffect(() => {
if (daoAddress) {
if (daoAddress && onMountOnly.current) {
loadDao(utils.getAddress(daoAddress)).then(_node => {
const errorNode = _node as WithError;
if (!errorNode.error) {
Expand Down Expand Up @@ -79,6 +80,7 @@ export function DaoNode({
});
}
});
onMountOnly.current = false;
}
}, [loadDao, daoAddress, fractalNode?.nodeHierarchy.childNodes, depth]);

Expand Down

0 comments on commit 236b8c3

Please sign in to comment.