-
Notifications
You must be signed in to change notification settings - Fork 95
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
How to use this sunburst in React? #85
Comments
@matter13311 this is not a React component, thus you cannot use it directly in a React environment directly. react-kapsule offers a means to do that easily, but there are other ways you can achieve the same. |
Could you give an example with react-kapsule? |
Something along these lines: import fromKapsule from 'react-kapsule';
import sunburstKapsule from 'sunburst-chart';
const Sunburst = fromKapsule(sunburstKapsule); then use it in React: <Sunburst data={myData} /> |
Thanks for the fast reply! Your example was also my intuition but trying it out in yields the following typeerror:
|
did you figured it out? |
No, I ended up not using react-kapsule. Just generated the chart and applied it to a div with an id, something to this effect:
And some extra logic to delete the children of the div when |
I ended up with an implementation similar to above, but was still getting the chart duplication error. As @hallundbaek hints here,
we need to provide a cleanup function to the useEffect. This StackOverflow says exactly what to do, and I found it to be correct. Here's my final useEffect implementation. I used explicit props coming from the parent component and passed them to the chart.
where the component returns
@vasturiano I think we can mark this issue as closed. |
How do I use this npm package with React?
`
import React from 'react'
import Sunburst from 'sunburst-chart';
return(
< Sunburst/ >
)
`
I get an error saying Sunburst can't be used in JSX.
The text was updated successfully, but these errors were encountered: