Skip to content

Instantly share code, notes, and snippets.

View louis-young's full-sized avatar
💻
Probably building something with React 😄

Louis Young louis-young

💻
Probably building something with React 😄
View GitHub Profile
@louis-young
louis-young / index.tsx
Created November 7, 2022 14:35
useImperativeHandle with TypeScript and function components
import { forwardRef, useImperativeHandle, useRef } from "react";
export interface VideoProps {
source: string;
}
export interface VideoRef {
play: () => void;
pause: () => void;
}
@louis-young
louis-young / index.ts
Last active March 31, 2023 10:22
TypeScript invariant assertion function
export function invariant(condition: unknown, message: string): asserts condition {
if (!condition) {
throw new Error(message);
}
}
@louis-young
louis-young / index.tsx
Last active February 24, 2023 09:49
Generic React component with render prop
import type { ReactNode } from "react";
export type ObjectWithIdentifier = {
id: number;
};
export type ListProps<TItem> = {
items: TItem[];
render: (item: TItem) => ReactNode;
};