Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: store selected Element as State #88

Open
zirkelc opened this issue Oct 13, 2021 · 0 comments
Open

Question: store selected Element as State #88

zirkelc opened this issue Oct 13, 2021 · 0 comments

Comments

@zirkelc
Copy link

zirkelc commented Oct 13, 2021

I'm listening to the select and unselect events on nodes and edges and saving this as selectedElement state:

  React.useEffect(() => {
    cyRef?.on('select unselect', 'node, edge', (event) => {
        setSelectedElement(event.target);
    });

    return () => {
      cyRef && cyRef.off('select unselect');
    };
  }, [cyRef]); 

When I check the selectedElement state on the React Dev Tools, I see that I actually store an reference to an Array:
image

I think the selectedElement is type of SingularElementArgument, so a single item collection.

I was wondering if it does make any sense to store the element reference as state:
Would a second selection of the same element give me the same object reference again?
Would it make more sense to store the element.id()?

Are there any drawbacks when storing the element ref as state?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant