Coder Social home page Coder Social logo

Comments (3)

moklick avatar moklick commented on July 19, 2024

The getEdges function returns the store edges: https://github.com/xyflow/xyflow/blob/v11/packages/core/src/hooks/useReactFlow.ts#L37-L40

It will return whatever you passed as edges to the ReactFlow component. It's not a Connection or a short form of an edge.

from xyflow.

maliyshock avatar maliyshock commented on July 19, 2024

I see. Thank you!
But i am still kinda confused.
my edges has been set as an empty array const [edges, , onEdgesChange] = useEdgesState([]);
and these are my types

const edgeTypes = {
  "custom-edge": CustomEdge,
};

There is nothing else.

I think issue is coming from onConnect function where besides validation I have

    return setEdges(oldEdges => {
        // TODO: fix this hardcode later - there should be validation to the target input types and connection to specific one
        connection.sourceHandle = "source-0";
        connection.targetHandle = "target-0";

        // connection has id of source and target handles and also has id of source and target nodes itself
        return addEdge({ ...connection, type: "custom-edge" }, oldEdges);

So you can see that it is a connection and not an edge.
This code I got from one of the documentation examples. I think from here
https://reactflow.dev/examples/interaction/validation

Here you can see we set edges based on params argument

 const onConnect = useCallback((params) => setEdges((els) => addEdge(params, els)), []);

which have a Connection type

So instead of setting edges you are setting connections as edges

image

This cause misunderstandings, because I expect having edges in edges, not connections.

from xyflow.

moklick avatar moklick commented on July 19, 2024

Hey @maliyshock,

onConnect gets called when you connect two nodes. As a parameter it gets a connection, because it's not an edge yet. In your case you are using the helper function addEdge (a simple helper that adds an id and checks if that edge already exists) to create an edge of the connection.

from xyflow.

Related Issues (20)

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.