当前位置: 首页 > news >正文

react class改hooks写法

类头修改

export default class EditUseTable extends Component 

改为

export default function EditUseTable({})

参数修改

constructor(props) {super(props)const {dbRecord, type, currentRecord, readOnly, updateTaxAmount} = this.props

改为(主函数的参数)

export default function EditUseTable({dbRecord, type, currentRecord, readOnly, updateTaxAmount})

状态修改

this.state = {tableList: currentRecord?.bookList || [],visible: false,readOnly: readOnly,type: type,indexDbId: dbRecord.indexDbId,projectId: dbRecord.projectId,hasCostIndex: false,}

改为(不需要修改的状态直接去掉,直接用props参数就行)

    const [tableList,setTableList]=useState(currentRecord?.bookList || [])const [visible,setVisible]=useState(false)const [hasCostIndex,setHasCostIndex]=useState(false)

初始化函数修改

constructor(props) {……// 获取所有XX,根据当前记录上的list做处理if ('project' === type) {this.initIndexRemainInfo(dbRecord.projectId, currentRecord)}}

改为

useEffect(()=>{// 获取所有XX,根据当前记录上的list做处理if ('project' === type) {initIndexRemainInfo(dbRecord.projectId, currentRecord)}},[])

函数改const定义

async initIndexRemainInfo(projectId, currentRecord) {……}

改为

  const initIndexRemainInfo=async(projectId, currentRecord)=> {……}

this.state去掉

this.state.readOnly

改为

readOnly

注意缺少的state要加上
this指针去掉

    this.updateData(items, false)

改为

updateData(items, false)

setState改造

this.setState({ indexInfo: indices, hasCostIndex: true })

改为(注意缺少的state定义要补充,例本示例的const [indexInfo,setIndexInfo]=useState([]))

      setHasCostIndex(true)setIndexInfo(indices)

函数从类中获取的props改造
某函数里这样写

const { formContext, pactPage = '' } = this.props

改为补充到主函数参数里

export default function EditUseTable({bizContext:{ dbRecord, type, currentRecord, readOnly, updateTaxAmount },formContext, pactPage = ''}) {

render改造

render() {const columns = getColumns(type)return (<Box flex flexlayout={{ direction: 'column' }}></Box>)}

改为(去掉render()壳子)

return (<Box flex flexlayout={{ direction: 'column' }}></Box>)

其中return上面的代码const columns = getColumns(type)放到初始化里

  useEffect(() => {setColumns(getColumns(type))}, [])
http://www.lryc.cn/news/232207.html

相关文章:

  • 桂院校园导航 | 云上高校导航 云开发项目 二次开发教程 1.3
  • sscanf提取相应字符到数组
  • 本地开发环境和服务器传输数据的几种方法
  • LeetCode之二叉树
  • 论文学习——THE USTC SYSTEM FOR ADRESS-M CHALLENGE
  • 第一百七十五回 如何创建放射形状渐变背景
  • vue实现调用手机拍照、录像功能
  • WPF播放视频
  • 交换机如何配置BGP协议
  • 精通Nginx(14)-配置HTTPS
  • 封装一个简单的table组件
  • Avalonia UI框架介绍
  • 【入门篇】1.3 redis客户端之 jedis 高级使用示例
  • 使用CXF调用WSDL(二)
  • list.toArray
  • 2013年11月10日 Go生态洞察:Go语言四周年回顾
  • Ubuntu上使用SSH连接到CentOS系统
  • 【知识增强】A Survey of Knowledge-Enhanced Pre-trained LM 论文笔记
  • shell脚本之函数
  • 订水商城实战教程10-宫格导航
  • 【C++11】lambda表达式 | 包装器
  • 网络安全准入技术之MAC VLAN
  • MyBatis 操作数据库
  • 设计模式 -- 建造者模式(Builder Pattern)
  • 如何下载 Apache + PHP + Mysql 集成安装环境并结合内网穿透工具实现公网访问内网服务
  • 一招告别百度广告烦恼,同时效率提高100倍的几个常用搜索技巧!
  • 文件上传 [ACTF2020 新生赛]Upload1
  • 振南技术干货集:比萨斜塔要倒了,倾斜传感器快来!(1)
  • 手把手教你搭建属于自己的快递小程序
  • C# Onnx LSTR 基于Transformer的端到端实时车道线检测