简体   繁体   English

道具验证中缺少“类” - Linting

[英]'classes' is missing in props validation - Linting

I am experiencing some issue with the linting.我遇到了一些棉绒问题。 It has always worked but today is complaining about the props "classes".它一直有效,但今天抱怨道具“课程”。 I am using React Hooks.我正在使用 React Hooks。

My components have this structure我的组件具有这种结构

import { withStyles, WithStyles } from '@material-ui/core/styles'

interface Props extends WithStyles<typeof styles> {
  firstProps: string
  secondProps: number
  thirdProps: Function
}

const MyComponent = ({
  classes,
  firstProps,
  secondProps
  thirdProps
}: Props) => {
  ...my code...
}

export default withStyles(styles)(MyComponent)

I understand that I should pass the classes in the interface such as:我知道我应该通过接口中的classes ,例如:

interface Props extends WithStyles<typeof styles> {
  firstProps: string
  secondProps: number
  thirdProps: Function
  classes: {
  ... all my classes ..
  }
}

BUT this is something that I want to avoid because is crumbersome AND because I think export default withStyles(styles)(MyComponent) should be enough (as it were before today).但这是我想避免的事情,因为它很笨重而且因为我认为export default withStyles(styles)(MyComponent)应该足够了(就像今天之前一样)。

With the current code, I am getting a lot of lint errors such as:使用当前代码,我收到很多 lint 错误,例如:

'classes' is missing in props validation
'classes.img' is missing in props validation
'classes.currentSelect' is missing in props validation
'classes.todayDate' is missing in props validation

If you are using hooks why not use makeStyles?如果您使用钩子,为什么不使用 makeStyles?

https://material-ui.com/styles/basics/#hook-api https://material-ui.com/styles/basics/#hook-api

And if you are using it with typescript I would recommend using it with createStyles()如果您将它与 typescript 一起使用,我建议您将它与 createStyles() 一起使用

https://material-ui.com/styles/api/#createstyles-styles-styles https://material-ui.com/styles/api/#createstyles-styles-styles

SOLVED解决了

In package.json change "eslint-plugin-react": "^7.17.0", to "eslint-plugin-react": "7.20.0"package.json "eslint-plugin-react": "^7.17.0",更改为"eslint-plugin-react": "7.20.0"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM