Skip to main content
Brand and assets
Build
Monitor and contribute
/
Patterns & layouts
  • Overview
  • Layouts
  • PageLayout
  • FullPageLayout
  • Patterns
  • Forms & density
  • Composition (asChild)
  • Rich components
  • DataTable
    • useDataTable
    • DataTable
    • Examples
  • Composition (asChild)

Composition

Use the asChild prop to compose Murray's functionality onto alternative components.

Some components that render an element accept an asChild prop. When true, the component excepts a single child element. Instead of rendering its own element, it will pass all props to that child, merging together any event handling props.

As an example, if you want to use Murray's A, but still rely on React Router's Link behavior, you can do the following:

import { A } from "murray";
import { Link } from "react-router-dom";

const Component = () => (
<A asChild>
<Link to="/somepage?id=foo">Go somewhere</Link>
</A>
);

Caveats​

For the child to get the correct props, it must be a component and:

  • forward the ref
  • accept className to get the proper styles on web

Resources​

  • asChild documentation from Tamagui: it's the implemntation we rely on on
  • asChild concept as initially introduced by Radix
Edit this page
Previous
Forms & density
Next
Overview
  • Caveats
  • Resources