当我尝试在组件中接收对象时,出现错误。
在console log“react-dom.development.js:14887 Uncaught Error:Objects are not valid as a React child(found:object with keys {id,url,icon}).如果你想呈现一个子对象的集合,请使用数组。”this is data component when some id, url, ann icon I can't pass those data to Navbar component
export const social = [
{
id: 1,
url: 'https://www.twitter.com',
icon: <FaTwitter />,
},
{
id: 2,
url: 'https://www.facebook.com',
icon: <FaFacebook />,
},
{
id: 3,
url: 'https://www.linkein.com',
icon: <FaLinkedin />,
},
{
id: 4,
url: 'https://www.youtube.com',
icon: <FaYoutube />,
},
];
字符串I added some data in the data component in console there showing Objects are not valid as a React child (found: object with keys {id, url, icon})
个
import React from 'react';
import { social } from './data';
const Navbar = () => {
console.log(social);
return (
<nav>
<div>
{social.map((item: any, index) => {
return <li key={index}>{item}</li>;
})}
</div>
</nav>
);
};
export default Navbar;
型but without typescript variant I can receive all those data
个
1条答案
按热度按时间dl5txlt91#
你不能在JSX中渲染原始对象,你必须以某种方式塑造它们,例如:
字符串