"Deepest one wins"
Neglexis opened this issue · comments
Not sure what the difference is between the two examples.
BASIC
<Titled title={() => 'Example.com'}>
<h1>Welcome!</h1>
<Titled title={title => `Homepage | ${title}`} />
</Titled>;
DEEPEST ONE WINS
<Titled title={() => 'Example.com'}>
<Titled title={() => 'Homepage'} />
</Titled>;
I notice the former has the title
variable in the title
props, but how would this work with triple nested titles?
Actually, there's no difference. I just wanted to make it really clear that this pattern works even if you want to overwrite upstream titles (the same way how react-document-title or react-helmet work, although they don't give you an option to compose from you parent).
I notice the former has the title variable in the title props, but how would this work with triple nested titles?
The most inner nested will win. It's using reduce()
to go through all title functions from top to bottom.
Maybe I should just delete the second example? Or enhance it somehow so it's not confusing?
But then what explains the difference in output?
Homepage | Example.com
VS
Homepage
<Titled title={title => `Homepage | ${title}`} />
vs
<Titled title={() => 'Homepage'} />
<Titled title={() => 'Example.com'}>
<h1>Welcome!</h1>
<Titled title={title => `Homepage | ${title}`}>
<Titled title={title => `Subpage | ${title}`} />
</Titled>
</Titled>;
would produce
Subpage | Homepage | Example.com