# react > React framework for building user interfaces. Use for React components, hooks, state management, JSX, and modern frontend development. Use when: working with React, creating components, managing state, handling side effects, building SPAs, or when user mentions React, component, 元件, hook, useState, useEffect, JSX, 前端開發, frontend. Triggers: "React", "component", "元件", "hook", "useState", "useEffect", "useContext", "useRef", "JSX", "props", "state", "前端開發", "單頁應用", "SPA" - Author: wangsc522 - Repository: wangsc2024/skills - Version: 20260119111409 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/wangsc2024/skills - Web: https://mule.run/skillshub/@@wangsc2024/skills~react:20260119111409 --- --- name: react description: | React framework for building user interfaces. Use for React components, hooks, state management, JSX, and modern frontend development. Use when: working with React, creating components, managing state, handling side effects, building SPAs, or when user mentions React, component, 元件, hook, useState, useEffect, JSX, 前端開發, frontend. Triggers: "React", "component", "元件", "hook", "useState", "useEffect", "useContext", "useRef", "JSX", "props", "state", "前端開發", "單頁應用", "SPA" --- # React Skill Comprehensive assistance with react development, generated from official documentation. ## When to Use This Skill This skill should be triggered when: - Working with react - Asking about react features or APIs - Implementing react solutions - Debugging react code - Learning react best practices ## Quick Reference ### Common Patterns **Pattern 1:** API ReferenceComponents lets you hide and restore the UI and internal state of its children. Reference Usage Restoring the state of hidden components Restoring the DOM of hidden components Pre-rendering content that’s likely to become visible Speeding up interactions during page load Troubleshooting My hidden components have unwanted side effects My hidden components have Effects that aren’t running Reference You can use Activity to hide part of your application: When an Activity boundary is hidden, React will visually hide its children using the display: "none" CSS property. It will also destroy their Effects, cleaning up any active subscriptions. While hidden, children still re-render in response to new props, albeit at a lower priority than the rest of the content. When the boundary becomes visible again, React will reveal the children with their previous state restored, and re-create their Effects. In this way, Activity can be thought of as a mechanism for rendering “background activity”. Rather than completely discarding content that’s likely to become visible again, you can use Activity to maintain and restore that content’s UI and internal state, while ensuring that your hidden content has no unwanted side effects. See more examples below. Props children: The UI you intend to show and hide. mode: A string value of either 'visible' or 'hidden'. If omitted, defaults to 'visible'. Caveats If an Activity is rendered inside of a ViewTransition, and it becomes visible as a result of an update caused by startTransition, it will activate the ViewTransition’s enter animation. If it becomes hidden, it will activate its exit animation. An Activity that just renders text will not render anything rather than rendering hidden text, because there’s no corresponding DOM element to apply visibility changes to. For example, will not produce any output in the DOM for const ComponentThatJustReturnsText = () => "Hello, World!". Usage Restoring the state of hidden components In React, when you want to conditionally show or hide a component, you typically mount or unmount it based on that condition: {isShowingSidebar && ( )} But unmounting a component destroys its internal state, which is not always what you want. When you hide a component using an Activity boundary instead, React will “save” its state for later: This makes it possible to hide and then later restore components in the state they were previously in. The following example has a sidebar with an expandable section. You can press “Overview” to reveal the three subitems below it. The main app area also has a button that hides and shows the sidebar. Try expanding the Overview section, and then toggling the sidebar closed then open: App.jsSidebar.jsApp.jsReloadClearForkimport { useState } from 'react'; import Sidebar from './Sidebar.js'; export default function App() { const [isShowingSidebar, setIsShowingSidebar] = useState(true); return ( <> {isShowingSidebar && ( )}

Main content

); } Show more The Overview section always starts out collapsed. Because we unmount the sidebar when isShowingSidebar flips to false, all its internal state is lost. This is a perfect use case for Activity. We can preserve the internal state of our sidebar, even when visually hiding it. Let’s replace the conditional rendering of our sidebar with an Activity boundary: // Before{isShowingSidebar && ( )}// After and check out the new behavior: App.jsSidebar.jsApp.jsReloadClearForkimport { Activity, useState } from 'react'; import Sidebar from './Sidebar.js'; export default function App() { const [isShowingSidebar, setIsShowingSidebar] = useState(true); return ( <>

Main content

); } Show more Our sidebar’s internal state is now restored, without any changes to its implementation. Restoring the DOM of hidden components Since Activity boundaries hide their children using display: none, their children’s DOM is also preserved when hidden. This makes them great for maintaining ephemeral state in parts of the UI that the user is likely to interact with again. In this example, the Contact tab has a