Function withForEach

  • Experimental

    Like Array.map but for React components. Concatenates components for each item in array, range or object

    It needs to discuss its name

    Type Parameters

    • IndexName extends string

    • ValueName extends string

    Parameters

    Returns Hoc<[SetOptionalFn<([IndexName & ""] extends [never]
        ? IndexName
        : "i") | ([ValueName & ""] extends [never]
        ? ValueName
        : "children")>]>

    Example

    const Component = withForEach(3)(Example)
    <Component {...props} />
    // is equivalent to
    <>
    <Example key={0} {...props} i={0} />
    <Example key={1} {...props} i={1} />
    <Example key={2} {...props} i={2} />
    </>

    Example

    const Component = withForEach(["a", "b"])(Example)
    <Component {...props} />
    // is equivalent to
    <>
    <Example key={0} {...props} i={0}>a</Example>
    <Example key={1} {...props} i={1}>b</Example>
    </>

    Example

    const Component = withForEach({
    a: 100,
    b: 200,
    })(Example)
    <Component {...props} />
    // is equivalent to
    <>
    <Example key="a" {...props} i="a">100</Example>
    <Example key="b" {...props} i="b">200</Example>
    </>

Generated using TypeDoc