Redux无状态组件(函数式组件)的使用(提升性能)

删除this,用props作为参数代替this.props

性能比类组件性能优秀

JSX语法必须引入React

TodoListUI.js

复制代码
import React from 'react'
import {Input,Button,List} from 'antd'

const TodoListUI=(props)=>{
    return (
        <div style={{margin:'10px'}}>
        <div><Input 
    placeholder={props.inputValue}
    style={{width:'250px',marginRight:'10px'}}
    onChange={props.changeInputValue}
    value={props.inputValue}
    />
    <Button type='primary'
        onClick={props.clickBtn}
    >增加</Button>
    </div>
    <div style={{margin:'10px',width:'300px'}}>
        <List 
        bordered 
        dataSource={props.list}
        // renderItem={(item,index)=>(<List.Item onClick={this.deleteItem.bind(this,index)}>{item}</List.Item>)}
        renderItem={(item,index)=>(<List.Item onClick={()=>{props.deleteItem(index)}}>{item}</List.Item>)}
       />
          
    </div>
    </div>
      );
 }
export default TodoListUI;
复制代码

 

posted @   SimoonJia  阅读(90)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示