react-helmet-async icon indicating copy to clipboard operation
react-helmet-async copied to clipboard

Possible bug with FilledContext type

Open DevanB opened this issue 5 years ago • 2 comments

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! 😄

DevanB avatar Sep 21 '18 18:09 DevanB

yes, would like a PR

staylor avatar Mar 10 '19 21:03 staylor

Hi @staylor, this is still an issue, isn't it? I'd invest some time and push a PR, if you agree.

natterstefan avatar Feb 07 '20 20:02 natterstefan