[英]Must use destructuring props assignment issue
我在 react-native 中制作了一個應用程序,當我嘗試將道具值之一放在文本上時,我收到如下錯誤消息: Must use destructuring props assignment
代碼是這樣的:
<Text style={styles.SubTextButton}>
{props.date1} - {props.date2}
</Text>
道具看起來像這樣:
(props: {
text: string
date1: string
date2: string
})
問題是,這實際上不會破壞我的應用程序並且一切正常。 但是我想知道這是否可能是代碼編寫中的格式問題,甚至是ESlinter的錯誤。
您收到此警告是因為在您的 Eslint 中設置了規則: "react/destructuring-assignment": [<enabled>, 'always']
Eslint 希望您使用解構賦值以這種方式編寫:
const MyComponent = ({ date1, date2 }) => {
return (
<Text>
{date1} - {date2}
</Text>
)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.