zoukankan      html  css  js  c++  java
  • React之无状态组件

    React之无状态组件可以TodoListUI组件对比

    无状态组件的优点:性能更高,因为他就是一个函数,TodoLIstUI组件是一个类,还需要执行其中的生命周期函数

    import React, { Component } from 'react'
    import 'antd/dist/antd.css'
    import { Input, Button, List } from 'antd'
    
    const TodoListUI = (props) => {
        return (
          <div style={{marginTop: '10px', marginLeft: '10px'}}>
            <div>
              <Input
                value={props.inputValue}  
                placeholder='todo info' 
                style={{ '300px', marginRight: '10px'}} 
                onChange={props.handleInputChange}
              />
              <Button type="primary" onClick={props.handleBtnClick}>提交</Button>
            </div>
            <List
              style={{marginTop: '10px',  '300px'}}
              bordered
              dataSource={props.list}
              renderItem={(item, index) => (<List.Item onClick={(index) => {props.handleItemDelete(index)}} >{item}</List.Item>)}
            />
          </div>
        )
    }
    
    // class TodoLisetUI extends Component {
    //   render () {
    //     return (
    //       <div style={{marginTop: '10px', marginLeft: '10px'}}>
    //         <div>
    //           <Input
    //             value={this.props.inputValue}  
    //             placeholder='todo info' 
    //             style={{ '300px', marginRight: '10px'}} 
    //             onChange={this.props.handleInputChange}
    //           />
    //           <Button type="primary" onClick={this.props.handleBtnClick}>提交</Button>
    //         </div>
    //         <List
    //           style={{marginTop: '10px',  '300px'}}
    //           bordered
    //           dataSource={this.props.list}
    //           renderItem={(item, index) => (<List.Item onClick={(index) => {this.props.handleItemDelete(index)}} >{item}</List.Item>)}
    //         />
    //       </div>
    //     )
    //   }
    // }
    
    export default TodoListUI
    
    
    今天你学习了吗!!!
  • 相关阅读:
    centos ssh远程登陆
    Vim 技巧
    php and js to facebook登陆 最佳实践
    vim 编辑器常规操作
    js 函数定义三种方式
    ORDER BY 默认升序排列
    sql = 和<>遵循的sql-92标准的设置SET ANSI_NULLS ON
    添加FB登陆时,需要curl扩展
    array(1) { [0]=> int(5) }和array(1) { [0]=> string(1) "5" }
    Android第三方推送引擎比较
  • 原文地址:https://www.cnblogs.com/nayek/p/12383183.html
Copyright © 2011-2022 走看看