react 报 Uncaught Error: Objects are not valid as a React child (found: object with keys {})

react 报

Uncaught Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead.in…
今天碰到了一个react报这个错误的;查找了一下 原来是因为在render的时候 没有点上对象的key名字,

比如:` 
{tableData.legendData.map((item: string, index: number) => (
{item}
))}
`

tableData.legendData里面有个项,是对象(‘{}’);item没有点上对象的key

    可以写成` 
{tableData.legendData.map((item: string, index: number) => (
{item || item[对象的key]}
))}
`

你可能感兴趣的:(react)