react-helmet: TS2786: 'Helmet' cannot be used as a JSX component
Helmet works in JSX but not in Typescript, I am getting:
TS2786: 'Helmet' cannot be used as a JSX component
Type 'Helmet' is missing the following properties from type 'ElementClass':
render, context, setState, forceUpdate
import { Helmet } from 'react-helmet';
return (
<>
<Helmet>
<title>
{translation('supportPage.heading')}
</title>
</Helmet>
<Breadcrumbs />
...
</>
);
react@17.0.1
react-helmet@6.1.0
@types/react-helmet@6.1.1 (devDependencies)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 21
- Comments: 22
Commits related to this issue
- add ts-ignore for react-helmet Workaround for issue https://github.com/nfl/react-helmet/issues/646 — committed to gagahpangeran/gagahpangeran.com by gagahpangeran 2 years ago
+1 Similar issue with react 18
also experiencing issues with this once upgrading to react-18
Wrapper did not work in our case while we attempted to upgrade a TypeScript project to React 18. The supposed fix was to have the latest
@types/reactas a resolution in thepackage.json:@Pixelatex I added
{/* @ts-ignore */}above where i used the Helmet component as this doesn’t seem like an impactful issue to me.Hi, I had the same issue. I found out that in my node_modules (or yarn cache), I had @types/react v17 and v18, even though I only had v18 in my
package.json. I deleted the entry for v17 (@types/react only) in my yarn.lock, re-ranyarn, and it worked. I must not have updated react typings cleanly.I have the same issue on my side with last versions of
react-helmetand its@types/react-helmet. I’ve just solved it by removing the@types/react-helmetpackage and addingdeclare module "react-helmet";to a.d.tsfile instead.How should I solve this problem? Still can’t solve it?
https://github.com/staylor/react-helmet-async/issues/154
For those of you guys who are having a TS error after upgrading to react 18, you can try adding a simple wrapper for
Helmet:Ah yea of course! That will do for now! Thank you @EVASIVE!