• react 中文文档案例二 (头像时间)


    import React from 'react';
    import ReactDOM from 'react-dom';
    
    function formatDate(date) {
        return date.toLocaleDateString();
    }
       
    const comment = {
        date: new Date(),
        text: 'I hope you enjoy learning React!',
        author: {
          name: 'Hello Kitty',
          avatarUrl: 'https://placekitten.com/g/64/64',
        },
    };
      // 提取头像
    function Avatar(props) {
        return (
          <img className="Avatar"
            src={props.user.avatarUrl}
            alt={props.user.name}
          />
      
        );
    }
      // 提取用户信息
    function UserInfo(props) {
        return (
          <div className="UserInfo">
            <Avatar user={props.user} />
            <div className="UserInfo-name">
              {props.user.name}
            </div>
          </div>
        );
    }
    function Comment(props) {
        return (
          <div className="Comment">
            <UserInfo user={props.author}/>
            <div className="Comment-text">{props.text}</div>
            <div className="Comment-date">
              {formatDate(props.date)}
            </div>
          </div>
        );
    }
     
    ReactDOM.render(
        <Comment
          date={comment.date}
          text={comment.text}
          author={comment.author}
        />,
        document.getElementById('root')
    );
      
  • 相关阅读:
    洛谷P4979 矿洞:坍塌
    [SHOI2015]脑洞治疗仪
    洛谷P2135 方块消除
    洛谷P1436 棋盘分割
    洛谷P2796 Facer的程序
    浅谈位运算
    [SDOI2006]最短距离
    12耐心_预测未来
    11耐心_有效市场假说
    02C++条件变量
  • 原文地址:https://www.cnblogs.com/Lolita-web/p/10341943.html
Copyright © 2020-2023  润新知