๐Ÿš€ ๐ƒ๐ฒ๐ง๐š๐ฆ๐ข๐œ ๐“๐ข๐ญ๐ฅ๐ž๐ฌ ๐ข๐ง ๐‘๐ž๐š๐œ๐ญ: ๐๐ฎ๐ข๐œ๐ค ๐“๐ข๐ฉ


If you want to set a dynamic page title in React, you can just put a title tag inside your component. But thereโ€™s a catch:

โš ๏ธ Only one title should be rendered at a time. If more than one component adds a title at once, React will put all of them in the head, which can cause unexpected behavior in the browser and affect SEO.

{/* โŒ ๐š†๐š›๐š˜๐š—๐š */}
<๐š๐š’๐š๐š•๐šŽ>๐™ฑ๐š˜๐š˜๐š”๐š’๐š—๐š๐šœ {๐š™๐šŠ๐š๐šŽ}</๐š๐š’๐š๐š•๐šŽ>
{/* โœ… ๐™ฒ๐š˜๐š›๐š›๐šŽ๐šŒ๐š */}
<๐š๐š’๐š๐š•๐šŽ>{
๐™ฑ๐š˜๐š˜๐š”๐š’๐š—๐š๐šœ ${๐š™๐šŠ๐š๐šŽ}}</๐š๐š’๐š๐š•๐šŽ>

The first one ends up creating an array ([“Bookings”, page]) instead of a string, so it doesnโ€™t work properly. Using a template literal fixes it.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *