Skip to content

hoepfnerdennis/ts-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published