react-doctor/no-polymorphic-children
Expose explicit subcomponents (`<Button.Text>`, `<Button.Icon>`) so consumers don't need to switch on `typeof children`
- Category: Architecture
- Severity: warn
- Source:
oxlint-plugin-react-doctor - Framework: global
- Enabled when: always
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Rule fires on a BinaryExpression of the form typeof children === 'string' (or ==), in either operand order. Targets components that branch their render shape based on what the consumer passed. Confirm children here is the component prop and not a local variable shadowing the name, and that the branch actually changes rendering rather than performing pure normalization or validation.
Fix prompt
Use this once validation confirms the diagnostic is real.
Expose explicit subcomponents that encode the shape in the API — for example Button.Text for string content and Button.Icon for icons — so consumers spell out intent and TypeScript catches misuse at compile time. This is the compound component pattern used by Radix, Headless UI, and shadcn. See https://www.patterns.dev/react/compound-pattern
Related rules
More Architecture rules from the rules reference:
react-doctor/no-prop-types: Move propTypes to TypeScript types: `type Props = { value: number }; function Component(props: Props)` — React 19 ignores runtime propTypesreact-doctor/no-pure-black-background: Tint the background slightly toward your brand hue — e.g. `#0a0a0f` or Tailwind's `bg-gray-950`. Pure black looks harsh on modern displaysreact-doctor/no-react-children: Pass children as props or render them directly instead of calling React.Children methods.react-doctor/no-react-dom-deprecated-apis: Switch the legacy `react-dom` root API (`render` / `hydrate` / `unmountComponentAtNode`) to `createRoot` / `hydrateRoot` / `root.unmount()` from `react-dom/client`. Replace `findDOMNode` with a ref. The whole `react-dom/test-utils` entry point is removed in React 19 — use `act` from `react` and `fireEvent` / `render` from `@testing-library/react`. Only enabled on projects detected as React 18+.react-doctor/no-react19-deprecated-apis: Pass `ref` as a regular prop on function components — `forwardRef` is no longer needed in React 19+. Replace `useContext(X)` with `use(X)` for branch-aware context reads. Only enabled on projects detected as React 19+.