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

'InnerHTML' cannot be used as a JSX component, Its instance type 'DangerouslySetHtmlContent' is not a valid JSX element. #4

Open
deepaksood619 opened this issue Apr 19, 2022 · 5 comments
Labels
good first issue Good for newcomers

Comments

@deepaksood619
Copy link

Screenshot 2022-04-19 at 4 24 33 PM

What should be done here?

yarn -v
1.22.18

node -v
v17.9.0
@dotmobo
Copy link

dotmobo commented Jul 21, 2022

same here

@christo-pr christo-pr added the good first issue Good for newcomers label Aug 22, 2022
@christo-pr
Copy link
Owner

Sorry about late response, can you post more info on how are you using the module? Im looking a way to reproduce this issue

@refactorized
Copy link

refactorized commented Nov 15, 2022

Getting this too, deep within some company code, but I think the minimal case is just to use it as a JSX component...

here are the relevant lines, I think:

import HTMetalAF from 'dangerously-set-html-content';

interface EmbedProps { markup?: string; };

export const SomeEmbed = ({markup,...etc}: EmbedProps) => (
  <React.Fragment>
    <HTMetalAF html={markup} />
    {/* do whatever with ...etc */}
  </React.Fragment>
);

This code suddenly breaks when updating. Adding types is good, but maybe should be under a larger SemVer jump as this potentially breaks existing code even when working nominally. The issue here seems to be that internally the code returns an object of type {} but as a react component it's expected to return ReactNode (at least in my case).

In any event, the code had been working, and this seems to be a type issue, so I just re-any'ed the type to fix my build like this:

//...  
  const Danger = HTMetalAF as any;
  export const SomeEmbed = ({markup,...etc}: EmbedProps) => (
  <React.Fragment>
    <Danger html={markup} />
    {/* do whatever with ...etc */}
  </React.Fragment>
);

@christo-pr
Copy link
Owner

christo-pr commented Nov 15, 2022

Thanks @refactorized for sharing this. TBH I'm not sure if we should bump the version just for the types, since this declaration file has been the same this whole time, I'll see what I can do now that I have an example, but also feel free to just fix that declaration file and open a PR, maybe we could consider bump the version after that

@christo-pr
Copy link
Owner

christo-pr commented Nov 15, 2022

Hey @refactorized, just FYI, even with your example I'm not having any issues with TS, you only need to change the html prop to not be undefined in the interface:

interface EmbedProps {
  markup: string;
}

So still not sure how I can reproduce this error, but If you do and you can properly update the definition file, you could open a PR and I'll look at it so we can properly fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants