[英]How can I fix eslint: react/destructuring-assignment error?
const Container = (props) => { return ( <StyledDiv> <SmallScreenDiv>{props.children}</SmallScreenDiv> </StyledDiv> ); };
This is my code and error happens at {props.children}这是我的代码,错误发生在 {props.children}
how can I fix this eslint error?我该如何解决这个 eslint 错误?
You can also destruct your props like this:你也可以像这样破坏你的道具:
const Container = ({children}) => {
return (
<StyledDiv>
<SmallScreenDiv>{children}</SmallScreenDiv>
</StyledDiv>
);
};
There are two solution for this有两种解决方案
Disable the prefer-destructuring feature on the eslint禁用 eslint 上的首选解构功能
destructure your props解构你的道具
const Container = ({children}) => { return ( <StyledDiv> <SmallScreenDiv>{children}</SmallScreenDiv> </StyledDiv> ); };
or或者
const Container = (props) => {
const {children} = props
return (
<StyledDiv>
<SmallScreenDiv>{children}</SmallScreenDiv>
</StyledDiv>
);
};
I will recommend to use second option.我会推荐使用第二个选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.