react 报 Objects are not valid as a React child (found: object with keys {}). If you meant to render.

使用react 报 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…

	*前段时间使用react;莫名其妙的报 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.这个错*

react 报 Objects are not valid as a React child (found: object with keys {}). If you meant to render._第1张图片

 render(){
	return (
		<div className = 'box'>
			{list.map((item,index)=>(
				<span>{ item }</span>
			))
			}
		</div>
	)
}
/*造成这个问题的原因就是 list数组下面有一条或者几条数组项是对象;
* 例如list 数组是[1,2,3,4,{name:"Muhammad Ali"}];
* 那么它一定会报上面的错;
* 
解析的时候加上一个三目问题就解决了
*/
{list.map((item,index)=>(
				<span>{ item.name===undefined?item:item.name }</span>
			))
	}

特此记录一下 有写的不对的地方请指正,有更好的解决办法的 请不吝赐教;咱们互相学习,共同进步

你可能感兴趣的:(react,react)