我在使用shouldComponentUpdate的TypeScript中遇到错误:



在组件中:

import React, { Component } from 'react'

class Hello extends Component<IProps, any> {
  shouldComponentUpdate(nextProps: IProps) { // error here
    console.log(nextProps, 'nextProps')
  }

  ....// some code
}

有人可以向我解释我在做什么错吗?

最佳答案

将React与TypeScript一起使用会有些烦人,因为今天的最后一个并不包含所有必需的错误描述技巧。因此,您遇到的错误可能与return方法中未完成的shouldComponentUpdate调用绑定(bind)在一起。

接下来尝试看看会发生什么:

  shouldComponentUpdate(nextProps: IProps) { // error here
    console.log(nextProps, 'nextProps')
    return true
  }

09-20 22:52