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

2.0.2 • Public • Published

npm version

ts-utils

A collection of typescript utility types. Includes all type of stuff for mostly plain ts or react code.

Documentation

What's inside?

PolymorphicComponents

To handle polymorphic as-prop in react components

First create your polymorphic component

import type { PolymorphicComponent } from "@dnshpf/ts-utils";

const Box: PolymorphicComponent<"div"> = ({ as: As, ...props }) => {
  const Component = As || "div";
  return <Component {...props} />;
};

Then use it with the element you need

const Container = () => {
  return <Box as="span">Hello there!</Box>;
};

or another component

import Link from "my-components";

const Container = () => {
  return (
    <Box as={Link} href="/path">
      Hello there!
    </Box>
  );
};

Package Sidebar

Install

npm i @dnshpf/ts-utils

Weekly Downloads

1

Version

2.0.2

License

MIT

Unpacked Size

5.7 kB

Total Files

10

Last publish

Collaborators

  • dnshpf