Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stylesheet precedence example #7235

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/content/reference/react-dom/components/link.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ export default function SiteMapPage() {

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

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.

{/*FIXME: this doesn't appear to actually work -- I guess precedence isn't implemented yet?*/}
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>`.

<SandpackWithHTMLOutput>

Expand All @@ -172,17 +170,22 @@ export default function HomePage() {
<ShowRenderedHTML>
<FirstComponent />
<SecondComponent />
<ThirdComponent/>
...
</ShowRenderedHTML>
);
}

function FirstComponent() {
return <link rel="stylesheet" href="first.css" precedence="high" />;
return <link rel="stylesheet" href="first.css" precedence="first" />;
}

function SecondComponent() {
return <link rel="stylesheet" href="second.css" precedence="low" />;
return <link rel="stylesheet" href="second.css" precedence="second" />;
}

function ThirdComponent() {
return <link rel="stylesheet" href="third.css" precedence="first" />;
}

```
Expand Down
Loading