Skip to content

Commit

Permalink
Merge pull request #274 from liam-hq/remove-use-effect
Browse files Browse the repository at this point in the history
refactor: reduce useEffect usage in ERDContent component
  • Loading branch information
sasamuku authored Dec 16, 2024
2 parents 533a876 + 8109940 commit 90fae17
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 6 additions & 0 deletions frontend/.changeset/neat-squids-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

refactor: reduce useEffect
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useEdgesState,
useNodesState,
} from '@xyflow/react'
import { type FC, useCallback, useEffect } from 'react'
import { type FC, useCallback } from 'react'
import styles from './ERDContent.module.css'
import { ERDContentProvider, useERDContentContext } from './ERDContentContext'
import { RelationshipEdge } from './RelationshipEdge'
Expand Down Expand Up @@ -59,18 +59,13 @@ export const ERDContentInner: FC<Props> = ({
edges: _edges,
enabledFeatures,
}) => {
const [nodes, setNodes, onNodesChange] = useNodesState<Node>([])
const [edges, setEdges, onEdgesChange] = useEdgesState<Edge>([])
const [nodes, setNodes, onNodesChange] = useNodesState<Node>(_nodes)
const [edges, setEdges, onEdgesChange] = useEdgesState<Edge>(_edges)
const { relationships } = useDBStructureStore()
const {
state: { loading },
} = useERDContentContext()

useEffect(() => {
setNodes(_nodes)
setEdges(_edges)
}, [_nodes, _edges, setNodes, setEdges])

useInitialAutoLayout()
useActiveTableNameFromUrl()
useFitViewWhenActiveTableChange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const ERDRenderer: FC = () => {
<SidebarTrigger />
</div>
<TableDetailDrawerRoot>
<ERDContent nodes={nodes} edges={edges} />
<ERDContent key={nodes.length} nodes={nodes} edges={edges} />
<div className={styles.toolbarWrapper}>
<Toolbar />
</div>
Expand Down

0 comments on commit 90fae17

Please sign in to comment.