},
position: { x: 100, y: 125 },
},
- // output node
{
id: '3',
- type: 'output',
- // you can also pass a React component as a label
+ type: 'output', // output node
data: { label: 'Output Node' },
position: { x: 250, y: 250 },
},
@@ -52,11 +49,56 @@ const elements = [
{ id: 'e2-3', source: '2', target: '3' },
];
-const BasicFlow = () => ;
+export default () => ;
```
import Flow from './index';
-You can find more advanced examples in the [examples](reactflow.dev/examples/) section.
+## Basic Functionality
+
+We don’t do any state updates besides the positions. This means that you need to pass the functions to remove an element or connect nodes by yourself. You can implement your own ones or use the [helper functions](/docs/api/helper-functions/) that come with the library. Here you see an example of how to use the heler functions `removeElements` and `addEdge`.
+
+
+```jsx
+import React, { useState } from 'react';
+import ReactFlow, { removeElements, addEdge } from 'react-flow-renderer';
+
+const initialElements = [
+ {
+ id: '1',
+ type: 'input',
+ data: { label: 'Input Node' },
+ position: { x: 250, y: 25 },
+ },
+ {
+ id: '2',
+ data: { label: 'Another Node' },
+ position: { x: 100, y: 125 },
+ },
+];
+
+export default () => {
+ const [elements, setElements] = useState(initialElements);
+ const onElementsRemove = (elementsToRemove) =>
+ setElements((els) => removeElements(elementsToRemove, els));
+ const onConnect = (params) => setElements((els) => addEdge(params, els));
+
+ return (
+
+ );
+}
+```
+
+In this example you can connect nodes and remove selected nodes and edges with the delete key.
+
+import Basic from './BasicFunctions';
+
+
+
+You can find more advanced examples in the [examples](/examples/) section.
diff --git a/website/src/markdown/docs/index.md b/website/src/markdown/docs/index.md
index 61d562fe..436aad0b 100644
--- a/website/src/markdown/docs/index.md
+++ b/website/src/markdown/docs/index.md
@@ -12,5 +12,3 @@ React Flow is a library for building node-based applications. These can be simpl
* **Utils:** Snap-to-grid and graph [helper functions](#helper-functions)
* **Components:** [Background, Minimap and Controls](#components)
* **Reliable**: Written in [Typescript](https://www.typescriptlang.org/) and tested with [cypress](https://www.cypress.io/)
-
-In order to make this library as flexible as possible we don’t do any state updates besides the positions. This means that you need to pass the functions to remove an element or connect nodes by yourself. You can implement your own ones or use the helper functions that come with the library.
\ No newline at end of file
diff --git a/website/src/pages/index.js b/website/src/pages/index.js
index 5bbfbf26..1b10a467 100644
--- a/website/src/pages/index.js
+++ b/website/src/pages/index.js
@@ -163,24 +163,34 @@ const Home = () => {
A flow consists of nodes and edges (or just nodes). Together we call
them elements. You can pass a set of elements as a prop to the
- ReactFlow component. Hereby all elements need unique ids. A node
- needs a position and a label and an edge needs a source (node id)
- and a target (node id). This is the most basic for a flow. A simple
- flow could look like this:
+ ReactFlow component. A simple flow could look like this:
Node 2 }, position: { x: 100, y: 100 } },
{ id: 'e1-2', source: '1', target: '2', animated: true },
];
-const BasicFlow = () => ;`}
+export default () => ;`}
/>
+
+ You can find a detailed{' '}
+ entry point in the docs or
+ read our{' '}
+
+ blog post
+ {' '}
+ to get started.
+