Skip to content

Instantly share code, notes, and snippets.

@toky-nomena
Created February 20, 2025 14:55
Show Gist options
  • Save toky-nomena/53566afc2275736bc5afaa98b7dafad3 to your computer and use it in GitHub Desktop.
Save toky-nomena/53566afc2275736bc5afaa98b7dafad3 to your computer and use it in GitHub Desktop.
import {Children, type ReactNode} from 'react';
type RenderFn<T> = (item: T, index?: number) => ReactNode;
export const For = <T,>({
render,
each = [],
}: {
render: RenderFn<T>;
each?: T[];
}) => Children.toArray(each.map((item, index) => render(item, index)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment