Skip to content
Closed
Show file tree
Hide file tree
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
33 changes: 33 additions & 0 deletions src/content/learn/referencing-values-with-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,39 @@ export default function Chat() {

</Sandpack>

If you don't need the input to be controlled (e.g., no live validation or display elsewhere), you can skip state entirely and read the DOM value directly via a ref.

<Sandpack>

```js
import { useRef } from 'react';

export default function Chat() {
const inputRef = useRef(null);

function handleSend() {
setTimeout(() => {
alert('Sending: ' + inputRef.current.value);
}, 3000);
}

return (
<>
<input
ref={inputRef}
/>
<button
onClick={handleSend}>
Send
</button>
</>
);
}
```

</Sandpack>


</Solution>

</Challenges>
8 changes: 4 additions & 4 deletions src/content/learn/writing-markup-with-jsx.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Suppose that you have some (perfectly valid) HTML:
src="https://react.dev/images/docs/scientists/yXOvdOSs.jpg"
alt="Hedy Lamarr"
class="photo"
>
/>
<ul>
<li>Invent new traffic lights
<li>Rehearse a movie scene
Expand Down Expand Up @@ -106,7 +106,7 @@ export default function TodoList() {
src="https://react.dev/images/docs/scientists/yXOvdOSs.jpg"
alt="Hedy Lamarr"
class="photo"
>
/>
<ul>
<li>Invent new traffic lights
<li>Rehearse a movie scene
Expand Down Expand Up @@ -145,7 +145,7 @@ For example, you can use a `<div>`:
src="https://react.dev/images/docs/scientists/yXOvdOSs.jpg"
alt="Hedy Lamarr"
class="photo"
>
/>
<ul>
...
</ul>
Expand All @@ -162,7 +162,7 @@ If you don't want to add an extra `<div>` to your markup, you can write `<>` and
src="https://react.dev/images/docs/scientists/yXOvdOSs.jpg"
alt="Hedy Lamarr"
class="photo"
>
/>
<ul>
...
</ul>
Expand Down
Loading