react-helmet-async
react-helmet-async copied to clipboard
Possible bug with FilledContext type
I've been researching into this for a day or two now, and believe the type for FilledContext
needs to have the helmet
property as optional like so:
export type FilledContext = {
helmet?: HelmetData;
};
I believe this because if you follow the instructions in the Usage section of the README, we create an empty helmetContext
constant, however the helmet
property is currently marked as required. So when you try to destructure helmet
from helmetContext
, TS says there is no helmet
property (as declared earlier).
import React from 'react';
import { renderToString } from 'react-dom/server';
import Helmet, { HelmetProvider } from 'react-helmet-async';
const helmetContext = {};
const app = (
<HelmetProvider context={helmetContext}>
<App>
<Helmet>
<title>Hello World</title>
<link rel="canonical" href="https://www.tacobell.com/" />
</Helmet>
<h1>Hello World</h1>
</App>
</HelmetProvider>
);
const html = renderToString(app);
const { helmet } = helmetContext;
// helmet.title.toString() etc…
I'd love to create a PR for this, if this is in fact a correct fix.
Thanks! 😄
yes, would like a PR
Hi @staylor, this is still an issue, isn't it? I'd invest some time and push a PR, if you agree.