Skip to content

[@types/react] React Component does not allow returning an array of React Elements #41808

@Arttse

Description

@Arttse

If you know how to fix the issue, make a pull request instead.


Simple example code:

const ExampleComponent: FC<{}> = () => {
  // some data example
  const data = [{ name: '123' }, { name: '321' }];

  // return React Elements array
  return data.map(t => <div key={t.name}>{t.name}</div>);
};

Throws an error:

TS2322: Type '() => JSX.Element[]' is not assignable to type 'FC<{}>'.   Type 'Element[]' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)>'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions