Skip to content

Broken example in the setup documentation #23

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

Closed
emileber opened this issue Apr 15, 2022 · 3 comments
Closed

Broken example in the setup documentation #23

emileber opened this issue Apr 15, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@emileber
Copy link

emileber commented Apr 15, 2022

Someone asked on Stack Overflow about a simple detail in the setup documentation, and while trying to get it to work on my side, I figured that the documented example doesn't work out of the box.

To make it work, I needed to install a couple more dependencies then documented:

  • lodash
  • graphology-types

And I needed to update the code to the following:

export const LoadGraph = () => {
  // first change to the example
  const loadGraph = useLoadGraph();

  // also wrapped the graph instantiation side-effect
  useEffect(() => {
    const graph = new Graph();

    graph.addNode("first", {
      // Missing required position
      x: 1,
      y: 1,

      size: 15,
      label: "My first node",
      color: "#FA4F40"
    });

    // Calling the function that was missing from the example
    loadGraph(graph);
  }, [loadGraph]);

  // Returning null to get a valid component
  return null;
};

Edit react-sigma-example

I'm not even sure it's the best way to use react-sigma as I've never used it before, though the hello world style example is definitely broken.

@emileber emileber added the bug Something isn't working label Apr 15, 2022
@sim51
Copy link
Owner

sim51 commented Apr 15, 2022

I updated the doc following your advice.
I also added a link to code sandbox.

I hope it will help beginner user to use the lib.

Thanks a lot !

@emileber
Copy link
Author

It looks like the required coordinates are still missing and the wrong function is used to load the graph inside the effect.

  useEffect(() => {
    const graph = new Graph();

    // Missing the x and y options
    graph.addNode("first", { size: 15, label: "My first node", color: "#FA4F40" });

    // This should be "loadGraph", since useLoadGraph is the hook and it is an invalid usage to have it here
    useLoadGraph(graph);
  }, [loadGraph]);

sim51 added a commit that referenced this issue Apr 15, 2022
@emileber
Copy link
Author

Looks great, I'm going to close my issue as it's no longer relevant. Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants