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

Parent component <title> taking priority

Open gurnzbot opened this issue 8 years ago • 3 comments

#I have an app that loads data asynchronously and uses Helmet. I have a <Helmet> component in App.js, and in a child component Category.js.

Whenever category gets enough data that it can update the page

attribute, I expect that the child's Helmet component will override the App's title tag. <p>In <strong>App.js'</strong> render() method:</p> <pre><code><Helmet onChangeClientState={(newState) => console.log('Change app:', newState, 'Title: ' + this.props.siteInfo.site.title)} title={this.props.siteInfo.site.title} > <meta property="twitter:title" content={this.props.siteInfo.site.title} /> {urlTag} {linkTag} <meta property="og:title" content={this.props.siteInfo.site.title} /> <meta property="og:type" content="website" /> <meta property="og:description" content={this.props.siteInfo.site.title} /> {favicons.map(icon => { return icon })} </Helmet> </code></pre> <p>In <strong>Category.js'</strong> render() method:</p> <pre><code><Helmet onChangeClientState={(newState) => console.log('Change category:', newState, 'Title: ' + title)} title={title} > <meta property="og:title" content={title} /> <meta property="og:description" content={title} /> <meta property="twitter:title" content={title} /> </Helmet> </code></pre> <p>If I reload a category route, I expect the title tag to be the category once it's data comes back from the API. However it is always the site title rendered in App. I can see this because the App's <code>onChangeClientState</code> function is the last thing logged in the console. I would expect the Category's <code>onChangeClientState</code> to fire last.</p> <p>If I navigate around the site a bit (go to the homepage and back to the category) the result is what I expect. However, on a simple page refresh, the child component doesn't render it's Helmet title.</p> <p>I think I'm misunderstanding the flow of data within Helmet..?</p>

gurnzbot avatar Sep 15 '17 19:09 gurnzbot

thx I found the fix

Cosmin-Hodor avatar Dec 12 '22 15:12 Cosmin-Hodor

thx I found the fix

Mind sharing what was the fix? :)

elderapo avatar Jan 30 '24 12:01 elderapo

thx I found the fix

Mind sharing what was the fix? :)

Now reading back on my reply, no idea why I even replied with that. I'll look into it again and see what I have done back then as quite a lot of things have happened since back then and my memory lacks.

Cosmin-Hodor avatar Feb 07 '24 12:02 Cosmin-Hodor