Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 19.8 — Ref as a Prop, Context as Provider and Other Improvements
React · Example 2 of 4 React 19+

<Context> as a provider

No .Provider. The inner provider overrides the outer one, so the second badge always sees sepia. Both badges re-render on Switch because their parent App re-rendered.

React 19 removes everyday friction: function components receive ref as a normal prop, ref callbacks can return a cleanup function, <Context value> is a provider, hydration errors show one message with a diff, custom elements get properties instead of strings, and createRoot takes error reporting callbacks.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Convert a forwardRef SearchBox to React 19 and focus it from a parent button.

02

Write a ref callback that adds a keydown listener to a div and removes it in the cleanup.

Explain it without notes

01

How do you pass a ref to a function component in React 19, and what changed from React 18?

02

What do ref cleanup functions add, and how do they change the null call?

03

What do onCaughtError, onUncaughtError and onRecoverableError receive and when are they called?

04

How does React 19 handle props on custom elements?

<Context> as a provider React 19+

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Badge sees dark
Badge sees sepia
Badge sees light
Badge sees sepia