Frontendx
README.md
SOLUTION.md
main.tsxentry
App.tsx
App.css
index.html
vite.config.ts
Installed
react@^19.2.0
react-dom@^19.2.0

Switch-Case Component in React

Prompt

Implement a Switch/Case JSX component pattern — a clean alternative to long chains of ternary operators or if-else blocks in JSX. <Switch value={x}> inspects its children and renders only the <Case when={y}> where x === y. Must support a <Default> fallback child rendered when no Case matches.

Use React.Children.toArray to iterate all children. Filter to find the child where child.props.when === value. If none match and a Default child exists render it instead.
Test Results

Switch-Case Component in React

Implement a Switch/Case JSX component pattern — a clean alternative to long chains of ternary operators or if-else blocks in JSX. <Switch value={x}> inspects its children and renders only the <Case when={y}> where x === y. Must support a <Default> fallback child rendered when no Case matches.