@@ -43,11 +43,6 @@ export default define.page((ctx) => {
4343For more complex scenarios, or to set page metadata from
4444[ islands] ( /docs/concepts/islands ) , Fresh ships with the ` <Head> ` -component.
4545
46- > [ info] : The ` <Head> ` component is not dynamic by default. It will not
47- > automatically update the document title or other head elements on the client
48- > side when component state changes. The head elements are set during server
49- > rendering or initial page load.
50-
5146``` tsx routes/about.tsx
5247import { Head } from " fresh/runtime" ;
5348
@@ -64,6 +59,29 @@ export default define.page((ctx) => {
6459});
6560```
6661
62+ ### Dynamic head updates from islands
63+
64+ The ` <Head> ` component works in [ islands] ( /docs/concepts/islands ) too. When
65+ component state changes, the document head is updated automatically:
66+
67+ ``` tsx islands/MetaUpdater.tsx
68+ import { useState } from " preact/hooks" ;
69+ import { Head } from " fresh/runtime" ;
70+
71+ export default function MetaUpdater() {
72+ const [title, setTitle] = useState (" Welcome" );
73+
74+ return (
75+ <div >
76+ <Head >
77+ <title >{ title } </title >
78+ </Head >
79+ <button onClick = { () => setTitle (" Updated!" )} >Change title</button >
80+ </div >
81+ );
82+ }
83+ ```
84+
6785### Avoiding duplicate tags
6886
6987You might end up with duplicate tags, when multiple ` <Head /> ` components are
@@ -75,13 +93,15 @@ the matching element:
75933 . Check if an element with the same ` id ` attribute
76944 . Only for ` <meta> ` elements: Check if there is a ` <meta> ` element with the
7795 same ` name ` attribute
78- 5 . No matching element was found, Fresh will create a new one and append it to
96+ 5 . Only for ` <link> ` elements: Check if there is a ` <link> ` element with the
97+ same ` rel ` attribute
98+ 6 . No matching element was found, Fresh will create a new one and append it to
7999 ` <head> `
80100
81101When multiple ` <Head> ` components render an element with the same key, the
82- ** last one rendered wins** . Since Fresh renders top-down (app wrapper → layout →
83- route → page component), a route page can override defaults set in ` _app.tsx ` by
84- using the same ` key ` prop.
102+ ** last one rendered wins** . Since Fresh renders top-down (app wrapper -> layout
103+ -> route -> page component), a route page can override defaults set in
104+ ` _app.tsx ` by using the same ` key ` prop.
85105
86106> [ info] : The ` <title> ` -tag is automatically deduplicated, even without a ` key `
87107> prop.
0 commit comments