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
classNameto get the proper styles on web
Resources
asChilddocumentation from Tamagui: it's the implemntation we rely on onasChildconcept as initially introduced by Radix