sim51 / react-sigma

Sigma React component
https://sim51.github.io/react-sigma/
Other
158 stars 27 forks source link

Having access to the sigma container #20

Closed sim51 closed 2 years ago

sim51 commented 2 years ago

The only way to have access to the sigma container is to search it by its className (ie. sigma-container). But the container is stored inside the context of the lib : https://github.com/sim51/react-sigma-v2/blob/1.3.0/src/context.ts#L6

Solution : add a hook to have access to the sigma container or expose the context of the lib. I prefer solution 1, so the lib context is only for internal purpose, and I can expose what I really want

kaihirota commented 2 years ago

When I did

useEffect(() => {
    const container = sigmaContext.container
    ...

I got an error saying that the node which I'm trying to insert before is not a child of the current node. But when I use const container = document.getElementsByClassName('sigma-container')[0] instead, it works.

sim51 commented 2 years ago

in v2, the context is now exported : https://github.com/sim51/react-sigma/blob/main/packages/core/src/index.ts#L7