Skip to content

Commit cf8449b

Browse files
authored
Merge pull request xyflow#258 from wbkd/develop
feat(internals): export easy peasy hooks closes xyflow#257
2 parents d681197 + 94e7d4a commit cf8449b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ React Flow is a library for building node-based graphs. You can easily implement
2121
- [Minimap](#minimap)
2222
- [Controls](#controls)
2323
- [Helper Functions](#helper-functions)
24+
- [Access Internal State](#access-state)
2425
- [Examples](#examples)
2526
- [Development](#development)
2627
- [Testing](#testing)
@@ -363,6 +364,29 @@ Transforms pixel coordinates to the internal React Flow coordinate system
363364

364365
You can use these function as seen in [this example](/example/src/Overview/index.js#L40-L41) or use your own ones.
365366

367+
## Access Internal State
368+
369+
We are using [Easy Peasy](https://easy-peasy.now.sh/) for state handling.
370+
If you need to access the internal state you can use the `useStoreState` hook inside a child component of the React Flow component:
371+
372+
```javascript
373+
import ReactFlow, { useStoreState } from 'react-flow-renderer';
374+
375+
const NodesDebugger = () => {
376+
const nodes = useStoreState(state => state.nodes);
377+
378+
console.log(nodes);
379+
380+
return null:
381+
}
382+
383+
const Flow = () => (
384+
<ReactFlow elements={elements}>
385+
<NodesDebugger />
386+
</ReactFlow>
387+
);
388+
```
389+
366390
## Examples
367391

368392
You can find all examples in the [example](example) folder or check out the live versions:

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export { isNode, isEdge, removeElements, addEdge, getOutgoers } from './utils/gr
99

1010
export * from './additional-components';
1111
export * from './types';
12+
export * from './store/hooks';

0 commit comments

Comments
 (0)