@spark-web/utils
TypeScript icon, indicating that this package has built-in type declarations

5.0.0 • Public • Published

title: Utilities isExperimentalPackage: true

🚧 — Under construction

forwardRefWithAs

A best effort attempt to provide strongly typed polymorphic components that (as the name suggests) forwards the ref onto the underlying element.

Internally this is used for our layout primitives (Box, Columns, Container, Hidden, Inline, Row and Stack), our link components (Link, ButtonLink and TextLink), our typographic components (Heading and Text) and finally VisuallyHidden.

export const PolymorphicComponent = forwardRefWithAs<
  'div',
  PolymorphicComponentProps
>(({ as: Tag = 'div', ...consumerProps }, forwardedRef) => {
  return (
    <Tag
      {...consumerProps}
      ref={forwardedRef}
      // Custom props go here
    />
  );
});

Readme

Keywords

none

Package Sidebar

Install

npm i @spark-web/utils

Weekly Downloads

1,258

Version

5.0.0

License

none

Unpacked Size

43.3 kB

Total Files

36

Last publish

Collaborators

  • brighte
  • brighte-release-bot