简体   繁体   中英

Must use destructuring props assignment issue

I was making an app in react-native and when I try to put on text one of the values of props, I get an error message like this: Must use destructuring props assignment

The code is this:

<Text style={styles.SubTextButton}>
      {props.date1} - {props.date2}
</Text>

and the props look like this:

(props: {
  text: string
  date1: string
  date2: string
})

The thing is, this actually don't ruin my app and all work well. But I would like to know if it is maybe a question of format in the writing of the code or even an error of the ESlinter.

You get this warning because in your Eslint set the rule: "react/destructuring-assignment": [<enabled>, 'always']

Eslint wants you write in this way with using destructuring assignment:

const MyComponent = ({ date1, date2 }) => {
  return (
    <Text>
      {date1} - {date2}
    </Text>
  )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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