--- id: wiki-2026-0508-jsx title: JSX category: 10_Wiki/Topics status: verified canonical_id: self aliases: [JavaScript XML, React JSX, TSX] duplicate_of: none source_trust_level: A confidence_score: 0.95 verification_status: applied tags: [jsx, react, typescript, transpilation] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: typescript framework: react --- # JSX ## 매 한 줄 > **"매 syntactic sugar over `createElement` — XML-like JS expression"**. React 의 발명, 매 declarative UI 의 핵심. 매 `
x
` → `jsx('div', null, 'x')` 로 transpile. 2026 default 는 **automatic runtime** (`react/jsx-runtime`) — 매 `import React` 의 불필요. ## 매 핵심 ### 매 transpile model - **Classic runtime** (legacy): `
` → `React.createElement('div', null)` — 매 file 마다 `import React` 필요. - **Automatic runtime** (2020+, default): `
` → `_jsx('div', null)`, runtime 의 자동 import. - **Preserve**: TS `--jsx preserve` — Babel 등 다른 tool 에 위임. ### 매 element types - **Lowercase** (`div`, `span`): 매 string tag, host component. - **Uppercase** (`Foo`): 매 reference, component identifier. - **Member access** (`Lib.Btn`): 매 namespaced component. - **Fragment** (`<>...`): 매 wrapper-less group. ### 매 응용 1. React / Preact / Solid / Qwik 의 매 component definition. 2. MDX — Markdown + JSX. 3. JSX as data (Astro, hyperscript variant). ## 💻 패턴 ### Automatic runtime (2026 default) ```tsx // tsconfig.json { "compilerOptions": { "jsx": "react-jsx", // 매 automatic runtime "jsxImportSource": "react" // or "preact", "@emotion/react" } } // Component.tsx — 매 import React 의 X export function Hello({ name }: { name: string }) { return

Hello, {name}

; } ``` ### Conditional rendering ```tsx function Status({ user }: { user?: User }) { if (!user) return null; return ( <> {user.isAdmin && } {user.posts.length > 0 ? : } ); } ``` ### Children pattern ```tsx type Props = { title: string; children: React.ReactNode }; function Card({ title, children }: Props) { return (

{title}

{children}
); } ``` ### Render prop / function-as-children ```tsx type DataLoaderProps = { url: string; children: (data: T | undefined, loading: boolean) => React.ReactNode; }; function DataLoader({ url, children }: DataLoaderProps) { const [data, setData] = useState(); const [loading, setLoading] = useState(true); useEffect(() => { fetch(url).then(r => r.json()).then(d => { setData(d); setLoading(false); }); }, [url]); return <>{children(data, loading)}; } ``` ### Polymorphic component (`as` prop) ```tsx type AsProp = { as?: C }; type PolymorphicProps = AsProp & React.ComponentPropsWithoutRef; function Box({ as, ...rest }: PolymorphicProps) { const Comp = as ?? 'div'; return ; } // 매 anchor props 의 typed ``` ### JSX spread + override ```tsx function PrimaryButton(props: React.ButtonHTMLAttributes) { return