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

Can not use as a JSX Component #17

Open
proeric opened this issue Feb 4, 2023 · 4 comments
Open

Can not use as a JSX Component #17

proeric opened this issue Feb 4, 2023 · 4 comments

Comments

@proeric
Copy link

proeric commented Feb 4, 2023

image

@vasturiano
Copy link
Owner

@proeric this is not a React component, so it cannot be used directly as such.

But you can easily convert it into one using react-kapsule.
You just need to do:

import fromKapsule from 'react-kapsule';
import circlePackChart from 'circlepack-chart';

const CirclePackComponent = fromKapsule(circlePackChart);

@unidesigner
Copy link

I'm having difficulty to loading it with react-kapsule in a Next.Js app:

import dynamic from 'next/dynamic'
import fromKapsule from 'react-kapsule'

const CirclePack = dynamic(
    () => {
        return import('circlepack-chart')
    },
    { ssr: false }
)

const CirclePackComponent = fromKapsule(CirclePack)

returns TypeError: kapsuleComponent is not a function.

Any help greatly appreciated!

@vasturiano
Copy link
Owner

vasturiano commented May 4, 2023

Most likely it has to do with dynamic not returning the import directly, because it's loading asynchronously.

@unidesigner
Copy link

I could solve it by wrapping in a separate component, i.e.

Use

import dynamic from 'next/dynamic'

const CirclePackComponent = dynamic(
    () => {
        return import('./CirclePack')
    },
    { ssr: false }
)

....

<CirclePackComponent data={data} width={300} height={300} />

with the CirclePack component

import fromKapsule from 'react-kapsule'
import circlePackChart from 'circlepack-chart'

const CirclePack = fromKapsule(circlePackChart)

export default function CirclePackComponent({ data, width, height }) {
    return <CirclePack data={data} width={width} height={height} />
}

Just in case someone else runs into the same issue.

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