diff options
author | Kirill Rogovoy <[email protected]> | 2021-07-29 17:37:51 +0300 |
---|---|---|
committer | Kirill Rogovoy <[email protected]> | 2021-07-29 17:37:59 +0300 |
commit | 293cb7160b7dfd20605da1a23ae6491deaf0e497 (patch) | |
tree | 0959d8229eba51665bae992f6d9f6cf2ad2ca846 | |
parent | 087f14ea0b7a4589d3a5c3a670c20b37d7e8d620 (diff) |
Refactoring: scopedLinks
-rw-r--r-- | pages/index.tsx | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/pages/index.tsx b/pages/index.tsx index c1d9a18..b3b7ab3 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -327,8 +327,8 @@ export const Graph = function (props: GraphProps) { const scopedNodeIds = scopedNodes.map((node) => node.id as string) - const scopedLinks = useMemo(() => { - return filteredLinks.filter((link) => { + const scopedGraphData = useMemo(() => { + const scopedLinks = filteredLinks.filter((link) => { // we need to cover both because force-graph modifies the original data // but if we supply the original data on each render, the graph will re-render sporadically const sourceId = typeof link.source === 'object' ? link.source.id! : (link.source as string) @@ -338,18 +338,14 @@ export const Graph = function (props: GraphProps) { scopedNodeIds.includes(sourceId as string) && scopedNodeIds.includes(targetId as string) ) }) - }, [filteredLinks, scopedNodes]) - const scopedGraphData = useMemo( - () => - scope.nodeIds.length === 0 - ? { nodes: filteredNodes, links: filteredLinks } - : { - nodes: scopedNodes, - links: scopedLinks, - }, - [filter, scope, JSON.stringify(Object.keys(nodeById))], - ) + return scope.nodeIds.length === 0 + ? { nodes: filteredNodes, links: filteredLinks } + : { + nodes: scopedNodes, + links: scopedLinks, + } + }, [filter, scope, JSON.stringify(Object.keys(nodeById))]) // make sure the camera position and zoom are fine when the list of nodes to render is changed useEffect(() => { |