-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added documentation for useInternalNode
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
sites/reactflow.dev/src/page-data/reference/hooks/useInternalNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { type PropsTableProps } from 'xy-shared'; | ||
|
||
export const signature: PropsTableProps = { | ||
props: [ | ||
{ name: 'Params' }, | ||
{ | ||
name: 'nodeId', | ||
type: 'string', | ||
description: 'The ID of a node you want to observe', | ||
}, | ||
{ name: 'Returns' }, | ||
{ | ||
name: '', | ||
type: 'InternalNode<T>', | ||
description: 'The InternalNode object for the node with the given ID', | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
sites/reactflow.dev/src/pages/api-reference/hooks/use-internal-node.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
title: useInternalNode | ||
description: 'This hook returns an InternalNode object for the given node ID.' | ||
--- | ||
|
||
import { PropsTable } from '@/components/props-table'; | ||
import { signature } from '@/page-data/reference/hooks/useInternalNode.ts'; | ||
|
||
# useInternalNode | ||
|
||
[Source on GitHub](https://github.com/xyflow/xyflow/blob/main/packages/react/src/hooks/useInternalNode.ts) | ||
|
||
This hook returns the internal representation of a specific node. Components that use this hook | ||
will re-render **whenever any node changes**, including when a node is selected | ||
or moved. | ||
|
||
```jsx | ||
import { useInternalNode } from '@xyflow/react'; | ||
|
||
export default function () { | ||
const internalNode = useInternalNode('node-1'); | ||
const absolutePosition = internalNode.internals.positionAbsolute; | ||
|
||
return ( | ||
<div> | ||
The absolute position of the node is at: | ||
<p>x: {absolutePosition.x}</p> | ||
<p>y: {absolutePosition.y}</p> | ||
</div> | ||
); | ||
} | ||
``` | ||
|
||
## Signature | ||
|
||
<PropsTable {...signature} /> | ||
|
||
## Typescript | ||
|
||
This hook accepts a generic type argument of custom node types. See this | ||
[section in our Typescript guide](/learn/advanced-use/typescript#nodetype-edgetype-unions) for more information. | ||
|
||
```tsx | ||
const internalNode = useInternalNode<CustomNodeType>(); | ||
``` |