Skip to content

Commit 4d77acd

Browse files
committed
add back code block with error message
1 parent a945321 commit 4d77acd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/content/learn/manipulating-the-dom-with-refs.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ export default function MyForm() {
378378

379379
Instead, the application crashes because `inputRef.current` is `null`, due to `<MyInput />` not passing the `ref` prop down to one of its children.
380380

381+
<ConsoleBlock level="error">
382+
Cannot read properties of null (reading 'focus')
383+
</ConsoleBlock>
384+
381385
This happens because by default React does not let a component access the DOM nodes of other components. Not even for its own children! This is intentional. Refs are an escape hatch that should be used sparingly. Manually manipulating _another_ component's DOM nodes makes your code even more fragile.
382386

383387
Instead, components that _want_ to expose their DOM nodes have to **opt in** to that behavior. A component can specify that it "forwards" its ref to one of its children by passing the `ref` prop down.

0 commit comments

Comments
 (0)