Movatterモバイル変換


[0]ホーム

URL:


Skip to Content
LearnQuick Start

Quick Start

This page will take you from zero to a working React Flow app in a few minutes. If youjust want to have a look around and get an impression of React Flow, check out ourinteractive no-codePlayground .

Installation

First, spin up a new React project however you like — we recommend usingVite 

npm init vite my-react-flow-app -- --template react

Nextcd into your new project folder and add@xyflow/react as a dependency

npm install @xyflow/react

Lastly, spin up the dev server and you’re good to go!

Usage

We will render the<ReactFlow /> component from the@xyflow/react package. That and defining a handful ofnodeobjects,edge objects andevent handlers are all we need to getsomething going! Get rid of everything insideApp.jsx and add the following:

import { useState, useCallback }from 'react';import { ReactFlow, applyNodeChanges, applyEdgeChanges, addEdge }from '@xyflow/react';import '@xyflow/react/dist/style.css';const initialNodes = [ { id:'n1', position: { x:0, y:0 }, data: { label:'Node 1' } }, { id:'n2', position: { x:0, y:100 }, data: { label:'Node 2' } },];const initialEdges = [{ id:'n1-n2', source:'n1', target:'n2' }];export default function App() { const [nodes,setNodes]= useState(initialNodes); const [edges,setEdges]= useState(initialEdges); const onNodesChange = useCallback( (changes)=> setNodes((nodesSnapshot)=> applyNodeChanges(changes, nodesSnapshot)), [], ); const onEdgesChange = useCallback( (changes)=> setEdges((edgesSnapshot)=> applyEdgeChanges(changes, edgesSnapshot)), [], ); const onConnect = useCallback( (params)=> setEdges((edgesSnapshot)=> addEdge(params, edgesSnapshot)), [], ); return ( <div style={{width:'100vw', height:'100vh' }}> <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} fitView /> </div> );}

There are two things to pay attention to here:

Result

Et voila. You’ve already created your first interactive flow!

Next steps

Core ConceptsCustomizationExamplesAPI ReferenceDiscordTemplate Projects
Last updated on
Overview

[8]ページ先頭

©2009-2026 Movatter.jp