在自定义路由组件中解决eslint错误"禁止道具扩散"的方法如下:
{
"rules": {
"react/jsx-props-no-spreading": "off"
}
}
// 父组件
import ChildComponent from './ChildComponent';
const ParentComponent = () => {
const propsToPass = {
prop1: 'value1',
prop2: 'value2',
// ...
};
return <ChildComponent {...propsToPass} />;
};
// 父组件
import ChildComponent from './ChildComponent';
const ParentComponent = () => {
const { prop1, prop2 } = props;
return <ChildComponent prop1={prop1} prop2={prop2} />;
};
请注意,以上答案仅供参考,具体解决方法可能因项目配置和需求而异。
领取专属 10元无门槛券
手把手带您无忧上云