2.0.2 • Published 2 years ago

@dnshpf/ts-utils v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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>
  );
};
2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago