use a redux state to store graph
Good day, thanks for the cool react-sigma! Can we use a redux state to store the object from which the graph is built? I didn't found such an option.
you wrote: I recommend you to NOT UPDATE those options to avoid performance issues, and to use a constant outside react component ( or use a useMemo). Sigma Sigma (and graphology) comes with methods that allow you to update graph but also settings. So you should treat it as an immutable component.
Now, can we use a redux state to store the object from which the graph is built, or it will cause performance problems? Should we use sigma.getGraph() to further add new elements to the graph or can we use changes in redux state to rebuilt the graph? This is a very common operation in our application.
Or what method do you recommend if we need to add new nodes and edges based after user action (they come from the backend)?
Yes you can use sigma.getGraph() to modify the graph without any issue ! I't's the recommanded way.
About redux, I'm not expert but to store object (and not only data) is generally a bad idea. The good way in redux will be to store the JSON value of the graph, and then on the component import it in graphology instance, which is the input of the sigma container.
By making that, you can (but not necessary) have performances issue.
On heavy graph, reload the graph or change its reducers take times.
Yes you can use
sigma.getGraph()to modify the graph without any issue ! I't's the recommanded way.About
redux, I'm not expert but to store object (and not only data) is generally a bad idea. The good way in redux will be to store the JSON value of the graph, and then on the component import it in graphology instance, which is the input of the sigma container. By making that, you can (but not necessary) have performances issue. On heavy graph, reload the graph or change its reducers take times.
Thank you! Please tell, which method in this case (to store the JSON value of the graph in redux state) is better to use to load changes of this JSON value into sigma component (to update graph)? Should we use https://sim51.github.io/react-sigma/docs/example/external_state or https://sim51.github.io/react-sigma/docs/example/load-graph ?
Both are doing pretty much the same thing, it depends on how you prefer writing code (outside the react sigma context or inside it). The external state give you access directly to the sigma API, whereas the loadGraph (or useSigma) is only available in a react sigma context. But under the hood, the laodgraph will call the same API as you will do with the external state.
react sigma is really close to the sigma API.