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

'ReactSVG' cannot be used as a JSX component. #2863

Open
atiribelli opened this issue Apr 10, 2024 · 0 comments
Open

'ReactSVG' cannot be used as a JSX component. #2863

atiribelli opened this issue Apr 10, 2024 · 0 comments

Comments

@atiribelli
Copy link

atiribelli commented Apr 10, 2024

I'm using a ReactSVG like this:

'use client'

import { ReactSVG } from "react-svg";

...

const Page = () => {

...

const attachTurnsToSvg = (elements = []) => {
 elements.forEach((element: SVGRectElement) => {
  //insert text inside SVGelements
 });
};

    const attachCallsToSvg = (elements = []) => {
        elements.forEach((element: SVGCircleElement) => {
            element.addEventListener('click', (e) => {
                console.debug('clicked', e);
            });
        });
    };

return(
<>
...
                <ReactSVG
                    src="/mysvg.svg" 
                    beforeInjection={(svg) => {
                        const svgWidth = (width !== undefined ? 0.625 * width : 1200);
                        const svgHeight = (height !== undefined ? 0.88 * height : 800);
                        svg.setAttribute('style', `width: ${svgWidth}px; height: ${svgHeight}px;`);
                      }}
                    afterInjection={(svg: { querySelectorAll: (arg0: string) => never[]; }) => {
                        const rects = svg?.querySelectorAll('rect.turnRect') || [];
                        attachTurnsToSvg(rects);
                        const circles = svg?.querySelectorAll('circle.callCircle') || [];
                        attachCallsToSvg(circles);
                    }}
                    className={styles.map} 
                />
</>)
}

export default Page;

and everything seems to works fine in development, however i got the errors:
"JSX element class does not support attributes because it does not have a 'props' property.",
'ReactSVG' cannot be used as a JSX component.
Its type 'typeof ReactSVG' is not a valid JSX element type.
Type 'typeof ReactSVG' is not assignable to type 'new (props: any, deprecatedLegacyContext?: any) => Component<any, any, any>'.
Type 'ReactSVG' is missing the following properties from type 'Component<any, any, any>': context, setState, forceUpdate, props, refs

and can't build the app.

Everything else works as i intended and i can't seem to find another solution to make it work...

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

1 participant