Reactjs 如何解决自定义路由组件中禁止道具传播的问题?
如何解决自定义路由组件中禁止道具传播的问题 eslint:禁止在3号线和6号线上传播道具Reactjs 如何解决自定义路由组件中禁止道具传播的问题?,reactjs,eslint,react-router-dom,Reactjs,Eslint,React Router Dom,如何解决自定义路由组件中禁止道具传播的问题 eslint:禁止在3号线和6号线上传播道具 const PrivateRoute = ({component: Component, ...rest}) => ( <Route {...rest} render={(props) => ( localStorage.getItem('user') ? <Component {...props} /> :
const PrivateRoute = ({component: Component, ...rest}) => (
<Route
{...rest}
render={(props) => (
localStorage.getItem('user') ?
<Component {...props} /> :
<Redirect to={{pathname: '/login', state: {from: props.location}}} />
)}
/>
);
const PrivateRoute=({component:component,…rest})=>(
(
localStorage.getItem('user')?
:
)}
/>
);
ES lint不鼓励使用道具撒布,以便不会将不需要的/意外的道具传递到组件。
详情如下:
要为特定文件禁用它,可以在组件文件的顶行放置:/*eslint disable react/jsx props no spreading*/
。
要对所有文件禁用它,请尝试以下操作:
根据以下答案编辑的评论对于ESLint很重要您使用哪种类型的评论,合法的是:
/* eslint-disable react/jsx-props-no-spreading */
谢谢你!我添加了一条规则“react/jsx props no spreading”:[“error”,{“custom”:“ignore”}],它解决了这个问题。。。我的头撞在墙上太久了。注释类型显然很重要。