Skip to content

Instantly share code, notes, and snippets.

@rohmanhm
Created March 28, 2023 03:21
Show Gist options
  • Save rohmanhm/b6a704114c0750fa1d38feeb549e1ece to your computer and use it in GitHub Desktop.
Save rohmanhm/b6a704114c0750fa1d38feeb549e1ece to your computer and use it in GitHub Desktop.

Refactor from

const CustomLink: React.PropsWithChildren<CustomLinkProps> = ({
  href,
  as,
  className,
  children,
  style = {},
  ...props
}) => {
  return (
    <Link href={href} as={as} passHref>
      <a
        className={cx(className, styles.detailsLink)}
        style={{
          color: fetchThemeColor({ color: 'system' }, 'action'),
          ...style,
        }}
        {...props}
      >
        {children}
      </a>
    </Link>
  );
};

to

const CustomLink = ({
  href,
  as,
  className,
  children,
  style = {},
  ...props
}: React.PropsWithChildren<CustomLinkProps>) => {
  return (
    <Link href={href} as={as} passHref>
      <a
        className={cx(className, styles.detailsLink)}
        style={{
          color: fetchThemeColor({ color: 'system' }, 'action'),
          ...style,
        }}
        {...props}
      >
        {children}
      </a>
    </Link>
  );
};

FIND

(const \w+): (React\.PropsWithChildren<\w+>) = \(\{([\s\S]*?)\}\) => \{

REPLACE

$1 = ({$3}: $2) => {
@rohmanhm
Copy link
Author

With optional props spread operator

(const \w+): (React\.PropsWithChildren<\w+>) = \((\{([\s\S]*?)\})?\) => \{

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment