<div class="container"></div>
const { ReactNode } = React;


const For = <T,>({
  v,
  children,
}: {
  v: [T, (v: T) => unknown, (v: T) => T];
  children: (v: T, index: number) => ReactNode;
}) => {
  let index = 0;
  const value: ReactNode[] = [];
  for (let i = v[0]; v[1](i); i = v[2](i)) {
    value.push(children(i, index++));
  }
  return <>{value}</>;
};

const ForTest = () => {
  return (
    <For v={[5, (i) => i < 10, (i) => i + 1]}>
      {(i, index) => (
        <button key={i}>
          {index}番目は{i}
        </button>
      )}
    </For>
  );
};
ReactDOM.render(<ForTest />, document.querySelector(".container"));


View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/16.8.6/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.6/umd/react-dom.production.min.js
  3. https://unpkg.com/@types/react@16.8.6/index.d.ts
  4. https://unpkg.com/@types/react-dom@16.8.6/index.d.ts
  5. https://unpkg.com/@types/react-dom@16.8.4/index.d.ts