react-force-graph icon indicating copy to clipboard operation
react-force-graph copied to clipboard

Question: can i return JSX to the nodeLabel prop in 3D

Open BarrieLAJ opened this issue 3 years ago • 2 comments

I want to render a React component in the nodeLabel prop

BarrieLAJ avatar Oct 25 '21 11:10 BarrieLAJ

@BarrieLAJ sorry that isn't currently supported. The longer answer is because this module is simply a React wrapper around 3d-force-graph, which is where the rendering takes place, and that is not aware of JSX syntax.

But, you can still pass HTML-like syntax in string format, like so:

.nodeLabel(node => `Node <b>${node.id}</b>`)

vasturiano avatar Nov 02 '21 23:11 vasturiano

@BarrieLAJ sorry that isn't currently supported. The longer answer is because this module is simply a React wrapper around 3d-force-graph, which is where the rendering takes place, and that is not aware of JSX syntax.

But, you can still pass HTML-like syntax in string format, like so:

.nodeLabel(node => `Node <b>${node.id}</b>`)

Okay that makes sense.

I used the ReactDOMServer.renderToString() method to convert my components to HTML string.

Here is the Docs reference. https://reactjs.org/docs/react-dom-server.html

BarrieLAJ avatar Nov 03 '21 00:11 BarrieLAJ