Перейти к содержимому

Polymorphic Сomponents

./components/polymorphic.tsx
export default function Polymorphic({as, children, ...rest}: any) {
const Component = as || "span";
return <Component {...rest}>{children}</Component>
}
// ...rest {...rest} - Добавляет вобзможность вставлять кастомные элементы
./app/page.tsx
import Polymorphic from "@/components/_corecss/polymorphic";
export default function Page() {
return (
<Polymorphic as='a' href="https://fubon.ru" target='_blank'>Polymorphic Сomponents</Polymorphic>
)
}