19
votes

"@types/react": "^16.7.17"
"@types/react-dom": "^16.0.11"
"typescript": "^3.2.2"

function ArryElement() {
  return [
    <div key='1'>1</div>,
    <div key='2'>2</div>
  ];
}

function App() {
  return <ArryElement />
}
1
It seems typescript does not allow you to return an array of elements from render. Simply use React.Fragment instead.Sulthan

1 Answers

27
votes

This is because React is expecting to return an object. What you do in this example, is return an array instead.

As a user mentioned above, wrapping it in a Fragment (which is an object) will solve the case