Skip to content

Commit 2f1803c

Browse files
committed
replacing <img> with <Image/>
1 parent 47e64bf commit 2f1803c

9 files changed

Lines changed: 14 additions & 14 deletions

src/content/learn/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ function MyButton() {
456456

457457
```
458458
459-
Then, *pass the state down* from `MyApp` to each `MyButton`, together with the shared click handler. You can pass information to `MyButton` using the JSX curly braces, just like you previously did with built-in tags like `<img>`:
459+
Then, *pass the state down* from `MyApp` to each `MyButton`, together with the shared click handler. You can pass information to `MyButton` using the JSX curly braces, just like you previously did with built-in tags like `<Image />`:
460460
461461
```js {11-12}
462462
export default function MyApp() {

src/content/learn/javascript-in-jsx-with-curly-braces.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ body > div > div { padding: 20px; }
381381
382382
<Solution>
383383
384-
Move the image URL into a property called `person.imageUrl` and read it from the `<img>` tag using the curlies:
384+
Move the image URL into a property called `person.imageUrl` and read it from the `<Image />` tag using the curlies:
385385
386386
<Sandpack>
387387
@@ -428,7 +428,7 @@ body > div > div { padding: 20px; }
428428
429429
In the object below, the full image URL is split into four parts: base URL, `imageId`, `imageSize`, and file extension.
430430
431-
We want the image URL to combine these attributes together: base URL (always `'https://react.dev/images/docs/scientists/'`), `imageId` (`'7vQD0fP'`), `imageSize` (`'s'`), and file extension (always `'.jpg'`). However, something is wrong with how the `<img>` tag specifies its `src`.
431+
We want the image URL to combine these attributes together: base URL (always `'https://react.dev/images/docs/scientists/'`), `imageId` (`'7vQD0fP'`), `imageSize` (`'s'`), and file extension (always `'.jpg'`). However, something is wrong with how the `<Image />` tag specifies its `src`.
432432
433433
Can you fix it?
434434

src/content/learn/passing-props-to-a-component.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ React components use *props* to communicate with each other. Every parent compon
2020

2121
## Familiar props {/*familiar-props*/}
2222

23-
Props are the information that you pass to a JSX tag. For example, `className`, `src`, `alt`, `width`, and `height` are some of the props you can pass to an `<img>`:
23+
Props are the information that you pass to a JSX tag. For example, `className`, `src`, `alt`, `width`, and `height` are some of the props you can pass to an `<Image />`:
2424

2525
<Sandpack>
2626

@@ -51,7 +51,7 @@ body { min-height: 120px; }
5151

5252
</Sandpack>
5353

54-
The props you can pass to an `<img>` tag are predefined (ReactDOM conforms to [the HTML standard](https://www.w3.org/TR/html52/semantics-embedded-content.html#the-img-element)). But you can pass any props to *your own* components, such as `<Avatar>`, to customize them. Here's how!
54+
The props you can pass to an `<Image />` tag are predefined (ReactDOM conforms to [the HTML standard](https://www.w3.org/TR/html52/semantics-embedded-content.html#the-img-element)). But you can pass any props to *your own* components, such as `<Avatar>`, to customize them. Here's how!
5555

5656
## Passing props to a component {/*passing-props-to-a-component*/}
5757

@@ -733,7 +733,7 @@ Although the syntax looks slightly different because you're describing propertie
733733

734734
#### Adjust the image size based on a prop {/*adjust-the-image-size-based-on-a-prop*/}
735735

736-
In this example, `Avatar` receives a numeric `size` prop which determines the `<img>` width and height. The `size` prop is set to `40` in this example. However, if you open the image in a new tab, you'll notice that the image itself is larger (`160` pixels). The real image size is determined by which thumbnail size you're requesting.
736+
In this example, `Avatar` receives a numeric `size` prop which determines the `<Image />` width and height. The `size` prop is set to `40` in this example. However, if you open the image in a new tab, you'll notice that the image itself is larger (`160` pixels). The real image size is determined by which thumbnail size you're requesting.
737737

738738
Change the `Avatar` component to request the closest image size based on the `size` prop. Specifically, if the `size` is less than `90`, pass `'s'` ("small") rather than `'b'` ("big") to the `getImageUrl` function. Verify that your changes work by rendering avatars with different values of the `size` prop and opening images in a new tab.
739739

src/content/learn/preserving-and-resetting-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ button {
18441844
18451845
#### Clear an image while it's loading {/*clear-an-image-while-its-loading*/}
18461846

1847-
When you press "Next", the browser starts loading the next image. However, because it's displayed in the same `<img>` tag, by default you would still see the previous image until the next one loads. This may be undesirable if it's important for the text to always match the image. Change it so that the moment you press "Next", the previous image immediately clears.
1847+
When you press "Next", the browser starts loading the next image. However, because it's displayed in the same `<Image />` tag, by default you would still see the previous image until the next one loads. This may be undesirable if it's important for the text to always match the image. Change it so that the moment you press "Next", the previous image immediately clears.
18481848

18491849
<Hint>
18501850

@@ -1918,7 +1918,7 @@ img { width: 150px; height: 150px; }
19181918

19191919
<Solution>
19201920

1921-
You can provide a `key` to the `<img>` tag. When that `key` changes, React will re-create the `<img>` DOM node from scratch. This causes a brief flash when each image loads, so it's not something you'd want to do for every image in your app. But it makes sense if you want to ensure the image always matches the text.
1921+
You can provide a `key` to the `<Image />` tag. When that `key` changes, React will re-create the `<Image />` DOM node from scratch. This causes a brief flash when each image loads, so it's not something you'd want to do for every image in your app. But it makes sense if you want to ensure the image always matches the text.
19221922

19231923
<Sandpack>
19241924

src/content/learn/reacting-to-input-with-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ Although this code is longer than the original imperative example, it is much le
505505
506506
#### Add and remove a CSS class {/*add-and-remove-a-css-class*/}
507507
508-
Make it so that clicking on the picture *removes* the `background--active` CSS class from the outer `<div>`, but *adds* the `picture--active` class to the `<img>`. Clicking the background again should restore the original CSS classes.
508+
Make it so that clicking on the picture *removes* the `background--active` CSS class from the outer `<div>`, but *adds* the `picture--active` class to the `<Image />`. Clicking the background again should restore the original CSS classes.
509509
510510
Visually, you should expect that clicking on the picture removes the purple background and highlights the picture border. Clicking outside the picture highlights the background, but removes the picture border highlight.
511511
@@ -698,7 +698,7 @@ body { margin: 0; padding: 0; height: 250px; }
698698
699699
</Sandpack>
700700
701-
Keep in mind that if two different JSX chunks describe the same tree, their nesting (first `<div>` → first `<img>`) has to line up. Otherwise, toggling `isActive` would recreate the whole tree below and [reset its state.](/learn/preserving-and-resetting-state) This is why, if a similar JSX tree gets returned in both cases, it is better to write them as a single piece of JSX.
701+
Keep in mind that if two different JSX chunks describe the same tree, their nesting (first `<div>` → first `<Image />`) has to line up. Otherwise, toggling `isActive` would recreate the whole tree below and [reset its state.](/learn/preserving-and-resetting-state) This is why, if a similar JSX tree gets returned in both cases, it is better to write them as a single piece of JSX.
702702
703703
</Solution>
704704

src/content/learn/render-and-commit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ img { margin: 0 10px 10px 0; }
124124

125125
</Sandpack>
126126

127-
* **During the initial render,** React will [create the DOM nodes](https://developer.mozilla.org/docs/Web/API/Document/createElement) for `<section>`, `<h1>`, and three `<img>` tags.
127+
* **During the initial render,** React will [create the DOM nodes](https://developer.mozilla.org/docs/Web/API/Document/createElement) for `<section>`, `<h1>`, and three `<Image />` tags.
128128
* **During a re-render,** React will calculate which of their properties, if any, have changed since the previous render. It won't do anything with that information until the next step, the commit phase.
129129

130130
<Pitfall>

src/content/learn/writing-markup-with-jsx.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ JSX looks like HTML, but under the hood it is transformed into plain JavaScript
181181

182182
### 2. Close all the tags {/*2-close-all-the-tags*/}
183183

184-
JSX requires tags to be explicitly closed: self-closing tags like `<img>` must become `<img />`, and wrapping tags like `<li>oranges` must be written as `<li>oranges</li>`.
184+
JSX requires tags to be explicitly closed: self-closing tags like `<Image />` must become `<img />`, and wrapping tags like `<li>oranges` must be written as `<li>oranges</li>`.
185185

186186
This is how Hedy Lamarr's image and list items look closed:
187187

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ These events fire only for the [`<details>`](https://developer.mozilla.org/en-US
176176
* [`onToggle`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDetailsElement/toggle_event): An [`Event` handler](#event-handler) function. Fires when the user toggles the details.
177177
* `onToggleCapture`: A version of `onToggle` that fires in the [capture phase.](/learn/responding-to-events#capture-phase-events)
178178

179-
These events fire for [`<img>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img), [`<iframe>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe), [`<object>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object), [`<embed>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed), [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link), and [SVG `<image>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/SVG_Image_Tag) elements. Unlike browser events, they bubble in React:
179+
These events fire for [`<Image />`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img), [`<iframe>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe), [`<object>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object), [`<embed>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed), [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link), and [SVG `<image>`](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/SVG_Image_Tag) elements. Unlike browser events, they bubble in React:
180180

181181
* `onLoad`: An [`Event` handler](#event-handler) function. Fires when the resource has loaded.
182182
* `onLoadCapture`: A version of `onLoad` that fires in the [capture phase.](/learn/responding-to-events#capture-phase-events)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ React supports all built-in browser HTML components. This includes:
9191
* [`<html>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html)
9292
* [`<i>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i)
9393
* [`<iframe>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe)
94-
* [`<img>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img)
94+
* [`<Image />`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img)
9595
* [`<input>`](/reference/react-dom/components/input)
9696
* [`<ins>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins)
9797
* [`<kbd>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd)

0 commit comments

Comments
 (0)