Skip to content

Commit bc93f05

Browse files
EricCotegaearon
andauthored
Fix stylesheet precedence example (#7235)
* Fix stylesheet precedence example * Update link.md --------- Co-authored-by: dan <[email protected]>
1 parent 51864f6 commit bc93f05

File tree

1 file changed

+10
-5
lines changed
  • src/content/reference/react-dom/components

1 file changed

+10
-5
lines changed

src/content/reference/react-dom/components/link.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ export default function SiteMapPage() {
151151

152152
### Controlling stylesheet precedence {/*controlling-stylesheet-precedence*/}
153153

154-
Stylesheets can conflict with each other, and when they do, the browser goes with the one that comes later in the document. React lets you control the order of stylesheets with the `precedence` prop. In this example, two components render stylesheets, and the one with the higher precedence goes later in the document even though the component that renders it comes earlier.
155-
156-
{/*FIXME: this doesn't appear to actually work -- I guess precedence isn't implemented yet?*/}
154+
Stylesheets can conflict with each other, and when they do, the browser goes with the one that comes later in the document. React lets you control the order of stylesheets with the `precedence` prop. In this example, three components render stylesheets, and the ones with the same precedence are grouped together in the `<head>`.
157155

158156
<SandpackWithHTMLOutput>
159157

@@ -165,23 +163,30 @@ export default function HomePage() {
165163
<ShowRenderedHTML>
166164
<FirstComponent />
167165
<SecondComponent />
166+
<ThirdComponent/>
168167
...
169168
</ShowRenderedHTML>
170169
);
171170
}
172171

173172
function FirstComponent() {
174-
return <link rel="stylesheet" href="first.css" precedence="high" />;
173+
return <link rel="stylesheet" href="first.css" precedence="first" />;
175174
}
176175

177176
function SecondComponent() {
178-
return <link rel="stylesheet" href="second.css" precedence="low" />;
177+
return <link rel="stylesheet" href="second.css" precedence="second" />;
178+
}
179+
180+
function ThirdComponent() {
181+
return <link rel="stylesheet" href="third.css" precedence="first" />;
179182
}
180183

181184
```
182185

183186
</SandpackWithHTMLOutput>
184187

188+
Note the `precedence` values themselves are arbitrary and their naming is up to you. React will infer that precedence values it discovers first are "lower" and precedence values it discovers later are "higher".
189+
185190
### Deduplicated stylesheet rendering {/*deduplicated-stylesheet-rendering*/}
186191

187192
If you render the same stylesheet from multiple components, React will place only a single `<link>` in the document head.

0 commit comments

Comments
 (0)