Coding

How to reuse React interface components with Claude Code

Use Radix for dialog behaviour, Sonner for save feedback and shadcn/ui for editable component styles. Then give Claude Code concrete behaviour to check.

Oliver · FoxAI World3 min read
18
Oliver holds color swatches beside a monitor showing colorful designs, with the Claude Code logo above.Reuse UI Components

Conceptual cover created with AI.

Ask Claude Code to add an Edit profile button to a React app and give it two things to get right. When the editor closes, the keyboard should take you back to the button that opened it. When saving finishes, the app should tell you how it went. Both belong in the task you give the coding assistant.

Start by asking Claude Code to inspect the components and dependencies already in the project. If you need a new piece, choose it by job. Radix Dialog provides the behaviour of a dialog window. Sonner handles short notifications. shadcn/ui gives you styled component code that you can edit in your project. Here is how those choices fit into one profile editor.

Give the dialog predictable keyboard behaviour

A modal is a window that makes the page behind it temporarily inactive. Radix Dialog keeps keyboard focus inside an open modal. Focus is the control that receives the next keystroke. Tab moves forward through the available controls, Shift+Tab moves backward, and Escape closes the dialog and returns focus to the button that opened it.

Give the profile dialog a meaningful title and description. Radix uses its Title and Description components to manage what screen readers announce. A title such as “Edit profile” tells someone where they are. A short description can explain which profile details they can change.

Oliver sits at a laptop beneath the Anthropic name, beside interface cards, a refresh symbol and a checkmark.
AI-generated conceptual illustration.

Show the result once the save finishes

Sonner is a React library for toasts, the short messages that appear temporarily on screen. Render its Toaster component at the root of the app, the top level of the interface. Then call toast.success when saving succeeds or toast.error when it fails. Trigger the message when you know the outcome, so a click on Save never gets mistaken for a completed save.

You can set where messages appear with position and how many are visible at once with visibleToasts. If your app already displays toasts, ask Claude Code to use that setup and check where the message appears in the profile flow.

Apply the project’s styles in one place

shadcn/ui distributes styled components as source code you can edit in your project. If the app uses its CSS-variable theming, shared names such as background and primary map to the page surface and main actions. Changing their values in the theme updates the components that use them. The profile dialog and its Save button can then follow the same design choices as the rest of the app.

For that editor, I would start by changing the shared theme values. A one-off change in a copied button applies only there. A shared value can carry the same visual decision across all the screens that use it.

Give Claude Code a task you can check

Keep recurring component choices in the project’s CLAUDE.md, a Markdown file Claude Code reads as context at the start of a session. Record the existing dialog and notification components to reuse. In the individual task, say what should happen. For example, ask Claude Code to reuse the profile dialog and the app’s toast setup, return focus to Edit profile on Escape, and show a message that matches the save result.

Check the result in the app. Open the editor with the keyboard. Use Tab and Shift+Tab to see whether focus stays inside. Press Escape and check that focus returns to Edit profile. Then try one successful save and one failed save, and look for the appropriate message each time. Those checks tell you whether the finished screen behaves as requested.

Ask AI about this article

Opens in a new tab with the question filled in.

Sources and research

Written by FoxAI World. The cover and illustrations are AI-generated conceptual artwork.

Your favourites

This list stays in this browser on your device. No account is needed, and other visitors cannot see it.

Use a story’s bookmark button to add your first favourite.