React key

function Blog(props) {
  const sidebar = (
    <ul>
      {props.posts.map((post) =>
        <li key={post.id}>
          {post.title}
        </li>
      )}
    </ul>
  );
  const content = props.posts.map((post) =>
    <div key={post.id}>
      <h3>{post.title}</h3>
      <p>{post.content}</p>
    </div>
  );
  return (
    <div>
      {sidebar}
      <hr />
      {content}
    </div>
  );
}
 
const posts = [
  {id: 1, title: 'Hello World', content: 'Welcome to learning React!'},
  {id: 2, title: 'Installation', content: 'You can install React from npm.'}
];
ReactDOM.render(
  <Blog posts={posts} />,
);

  

  {
    // key: 'project',
    key: "cloudProfile",
    name: '数据中心概况',
    icon: 'project',
    child:[
      {
        key: 'cloudProfilesa',
        name: '首页',
      },
      {
        key: 'cloudProfiles',
        name: '虚拟资源云平台概况',
      },
      {
        key: 'cloudProfilesc',
        name: '容器平台概况',
      }
    ]
  }

export default (props)=><User {...props} key={props.location.pathname} />

posted on 2020-05-20 20:32  左侧岚  阅读(154)  评论(0编辑  收藏  举报

导航