Coder Social home page Coder Social logo

xyflow / react-flow-example-apps Goto Github PK

View Code? Open in Web Editor NEW
123.0 4.0 64.0 5.5 MB

Example React Flow apps for Create React App, Next.js and Remix.

Home Page: https://reactflow.dev

License: MIT License

HTML 6.81% CSS 4.75% TypeScript 82.78% JavaScript 4.79% Astro 0.87%
reactflow graph-editor node-based-ui workflow-engine starterkit

react-flow-example-apps's Introduction

react-flow-example-apps's People

Contributors

moklick avatar peterkogo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-flow-example-apps's Issues

Errors in unchanged example source code -- reactflow-nextjs

  1. I downloaded this repo
  2. cd reactflow-nextjs-app-router
  3. yarn install
  4. view code in VS Code:

Error 1

❯ npx tsc

src/pages/_app.tsx:7:11 - error TS2786: 'Component' cannot be used as a JSX component.
  Its element type 'ReactElement<any, any> | Component<any, any, any> | null' is not a valid JSX element.
    Type 'Component<any, any, any>' is not assignable to type 'Element | ElementClass | null'.
      Type 'Component<any, any, any>' is not assignable to type 'ElementClass'.
        The types returned by 'render()' are incompatible between these types.
          Type 'React.ReactNode' is not assignable to type 'import("/Users/chris/projects/2-react-flow-example-apps/reactflow-nextjs/node_modules/@types/react-dom/node_modules/@types/react/ts5.0/index").ReactNode'.
            Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
              Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.

7   return <Component {...pageProps} />;
            ~~~~~~~~~

  node_modules/@types/react-dom/node_modules/@types/react/ts5.0/index.d.ts:378:9
    378         children: ReactNode;
                ~~~~~~~~
    'children' is declared here.

Found 1 error in src/pages/_app.tsx:7

Error 1 prevents the app from being built. It can be run via yarn run dev, but yarn run build fails.

May matter -- I'm running Node v21.7.1. Note the repo doesn't specify what Node version to use.

See related #5.

Errors in unchanged example source code -- reactflow-nextjs-app-router

  1. I downloaded this repo
  2. cd reactflow-nextjs-app-router
  3. yarn install
  4. view code in VS Code:

Error 1
image
That can be suppressed in VS Code only (not resolved) by preceding with // eslint-disable-next-line @next/next/no-async-client-component. When I run yarn run build, the build fails for the same issue: Type error: Type '{ children: Element; initialNodes: Node[]; initialEdges: Edge[]; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; }'. Property 'initialNodes' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }'.

Error 2
image
I haven't found a fix. This is likely a React 18 types issue. It would be helpful to know how you've solved it, if you have.

Error 3
image
This can be suppressed (not resolved) by preceding each size: line with // @ts-ignore TS2322.


Errors 2 and 3 are nuisance -- can be suppressed to reduce IDE noise, although that's not as safe as possible.

However error 1 prevents the app from being built. It can be run via yarn run dev, but yarn run build fails.

May matter -- I'm running Node v21.7.1. Note the repo doesn't specify what Node version to use.

See related #6.

Under cypress e2e testing, reactflow error #004 happens occasionally

Hi team, I'm using the nextjs example in this repository to reproduce the issue where reactflow onPaneClick handler doesnt receive the cypress ( "cypress": "^12.17.4") onClick event. The event is logged in console and I triggered the test manually via the cypress browser. After ten or more hits, I got index.js:150 [React Flow]: The React Flow parent container needs a width and a height to render the graph. Help: https://reactflow.dev/error#004 occasionally. To me, it doesnt seem to be any width/height error with the reactflow usages. Could anyone shred some light on this please? any ideas/suggestions would be appreciated.

onPaneClick handler

....
  const onPaneClick = useCallback((e: React.MouseEvent<Element, MouseEvent>) => {
    console.log('clicked', e);
  }, []);

  return (
    <div className={styles.flow}>
      <ReactFlow
        nodes={nodes}
        onNodesChange={onNodesChange}
        onPaneClick={onPaneClick}
.....

cypress script

describe('template spec', () => {
  it('passes', () => {
    cy.visit('http://localhost:3000')
    cy.get('.react-flow__pane')
    .click()
  })
})

cypress chrome console log

image

Please add an example in next.js with app router

I am trying the basic example using "reactflow": "^11.8.3" and "next": "13.4.19". I am using the app router of next.js. The nodes and edges are not rendered. The relevant html elements are not created. The same code works for pages router of next.js.

Adding code for reference

Root layout.js

import './globals.css'
import { Inter } from 'next/font/google'

const inter = Inter({ subsets: ['latin'] })

export const metadata = {
  title: 'Next-Reactflow App router',
  description: 'Generated by create next app',
}

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body className={inter.className}>{children}</body>
    </html>
  )
}

Flow page
layout.js

import styles from './flow.module.css';
export default function FlowLayout({children}) {
    return (
        <div className={styles.flow}>
            {children}
        </div>
    )
}

page.js

'use client'
import React from 'react';
import ReactFlow from 'reactflow';
import 'reactflow/dist/style.css';

const initialNodes = [
    { 
        id: '1', 
        position: { x: 100, y: 100 }, 
        data: { label: 'Node 1' } 
    },
    { 
        id: '2', 
        position: { x: 100, y: 200 }, 
        data: { label: 'Node 2' } 
    },
  ];
const initialEdges = [{ id: 'e1-2', source: '1', target: '2' }];

export default function Flow() {
    return (
        <ReactFlow 
            nodes={initialNodes}
            edges={initialEdges}
        />
    )
}

flow.module.css

.flow {
  width: 100vw;
  height: 100vh;
  background-color: white;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.