Skip to content

Instantly share code, notes, and snippets.

View its-monotype's full-sized avatar

its-monotype

  • Earth
View GitHub Profile
@its-monotype
its-monotype / withClassName.tsx
Last active December 11, 2022 17:47
withClassName React HOC (with forwardRef)
import React from 'react';
import clsx from 'clsx';
import { getDisplayName, __DEV__ } from '@/utils/helpers';
export type withClassNameProps = {
className?: string;
};
export function withClassName<T, P extends object>(
@its-monotype
its-monotype / withClassName.tsx
Created December 11, 2022 17:43
withClassName (no forwardRef)
export function withClassName<Props extends object>(
WrappedComponent:
| React.ComponentType<Props>
| React.ForwardRefExoticComponent<Props>,
classes?: string,
) {
const WithClassName = (props: Props & { className?: string }) =>
React.createElement(WrappedComponent, {
...props,
className: clsx(props.className, classes),
@its-monotype
its-monotype / parse-int-slug.pipe.ts
Created July 30, 2022 20:15
NestJS ParseIntSlugPipe. Useful when you need to get slug or id from param.
import {
ArgumentMetadata,
HttpStatus,
Injectable,
Optional,
PipeTransform
} from '@nestjs/common';
import {
ErrorHttpStatusCode,
HttpErrorByCode