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

Unable to use React components within the node HTML #38

Open
PeterBowater opened this issue Apr 27, 2020 · 5 comments
Open

Unable to use React components within the node HTML #38

PeterBowater opened this issue Apr 27, 2020 · 5 comments

Comments

@PeterBowater
Copy link

HI Pierre,

Was hoping you could shed some light here. In the demo code you have this for the renderNode parameter of the TreeViz call:

renderNode={(node) =>
<div style="height:${node.settings.nodeHeight}px;display:flex;align-items:center;margin-left:12px">Node name: ${node.data.text_1}</div>
}

Is there an accepted way to return a React component rather than constructing bare HTML?

If not, do you think it is possible it could be updated to do so?

Thanks very much,

Peter.

@PierreCapo
Copy link
Owner

Hello Peter, I realized yesterday that the treeviz-react wrapper is really broken.
I really don't have time to fix it in the incoming weeks sadly, but I think maybe google how to wrap a VanillaJs component in a react app, because the vanilla treeviz module should work smoothly

@PeterBowater
Copy link
Author

OK thanks Pierre, not to worry.

We'll explore other ways of incorporating, I'm sure we can work something out. If viable, I expect we will share it back to you if you wanted?

Thanks,

Peter

@PierreCapo
Copy link
Owner

Oh that would be awesome, please do @PeterBowater 😀

@phollaki
Copy link

phollaki commented Sep 15, 2021

Hey Guys! Did you find a solution for this or not yet? @PeterBowater @PierreCapo Is there a way to insert a React component like a Material ui icon to html template? For example something like this: result = <div style="height:${node.settings.nodeHeight}px;display:flex;align-items:center;margin-left:12px">Node name: ${node.data.text_1}${<Icon/>}</div>

@phollaki
Copy link

I found a solution for this problem. You have to import { renderToString } from "react-dom/server". After this you can create a constant for your component: const icon = renderToString(<AddIcon />);. And then you can use it in your HTML: ${icon}. Made an example in codesandbox if you would like to try. https://codesandbox.io/s/lingering-browser-iiqud?file=/src/App.js:526-570

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

3 participants