最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - import {useEdgesState, useNodesState} from "@xyflowreact" not working, showing Unhandled Runtime Err

programmeradmin1浏览0评论

I am using Next js and typescript for my project, while including Reactflow on my webstie it shows errors.

Here is my source code:

import { Workflow } from "@prisma/client";
import React from "react";
import { ReactFlow, useEdgesState, useNodesState } from "@xyflow/react";

import "@xyflow/react/dist/style.css";

function FlowEditor({ workflow }: { workflow: Workflow }) {

  const [nodes, setNodes, onChangeNodes] = useNodesState([]);
  const [edges, setEdges, onChangeEdges] = useEdgesState([]);


  return (
    <main className="h-full w-full">
      <ReactFlow
        nodes={nodes}
        edges={edges}
        onNodesChange={onChangeNodes}
        onEdgesChange={onChangeEdges}
      >

      </ReactFlow>
    </main>
  );
}

export default FlowEditor;

The error shows on the localhost :

the error image

or

    Unhandled Runtime Error
    Error: (0 , _xyflow_react__WEBPACK_IMPORTED_MODULE_3__.useNodesState) is not a function or its return value is not iterable
Source
app\workflow\_components\FlowEditor.tsx (9:58) @ FlowEditor

    
           7 | function FlowEditor({ workflow }: { workflow: Workflow }) {
           8 |
        >  9 |   const [nodes, setNodes, onChangeNodes] = useNodesState([]);
             |                                                          ^
          10 |   const [edges, setEdges, onChangeEdges] = useEdgesState([]);

Im expecting solutions of my problem and perfectly use of the pakege @xyflow/react or a better pakege for this type of component

I am using Next js and typescript for my project, while including Reactflow on my webstie it shows errors.

Here is my source code:

import { Workflow } from "@prisma/client";
import React from "react";
import { ReactFlow, useEdgesState, useNodesState } from "@xyflow/react";

import "@xyflow/react/dist/style.css";

function FlowEditor({ workflow }: { workflow: Workflow }) {

  const [nodes, setNodes, onChangeNodes] = useNodesState([]);
  const [edges, setEdges, onChangeEdges] = useEdgesState([]);


  return (
    <main className="h-full w-full">
      <ReactFlow
        nodes={nodes}
        edges={edges}
        onNodesChange={onChangeNodes}
        onEdgesChange={onChangeEdges}
      >

      </ReactFlow>
    </main>
  );
}

export default FlowEditor;

The error shows on the localhost :

the error image

or

    Unhandled Runtime Error
    Error: (0 , _xyflow_react__WEBPACK_IMPORTED_MODULE_3__.useNodesState) is not a function or its return value is not iterable
Source
app\workflow\_components\FlowEditor.tsx (9:58) @ FlowEditor

    
           7 | function FlowEditor({ workflow }: { workflow: Workflow }) {
           8 |
        >  9 |   const [nodes, setNodes, onChangeNodes] = useNodesState([]);
             |                                                          ^
          10 |   const [edges, setEdges, onChangeEdges] = useEdgesState([]);

Im expecting solutions of my problem and perfectly use of the pakege @xyflow/react or a better pakege for this type of component

Share Improve this question edited Jan 31 at 14:28 Shykat Himu asked Jan 31 at 14:21 Shykat HimuShykat Himu 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

add "use client"; on the top of the source code, this will fix the error

"use client";


import { Workflow } from "@prisma/client";
import React from "react";
import { ReactFlow, useEdgesState, useNodesState } from "@xyflow/react";

import "@xyflow/react/dist/style.css";

function FlowEditor({ workflow }: { workflow: Workflow }) {

  const [nodes, setNodes, onChangeNodes] = useNodesState([]);
  const [edges, setEdges, onChangeEdges] = useEdgesState([]);


  return (
    <main className="h-full w-full">
      <ReactFlow
        nodes={nodes}
        edges={edges}
        onNodesChange={onChangeNodes}
        onEdgesChange={onChangeEdges}
      >

      </ReactFlow>
    </main>
  );
}

export default FlowEditor;

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论