`
import React from 'react';
import BuildControl from './BuildControl/BuildControl';
import './BuildControl.css';
const controls = [{ label: 'Cheese', type: 'cheese' }, { label: 'Bacon', type: 'bacon' }, { label: 'Meat', type: 'meat' }, { label: 'Salad', type: 'salad' }];
const BuildControls = () => {
controls.map((ctrl) => {
console.log("ctrl is:", ctrl.label, ctrl.type);
return (<div className="BuildControls"><BuildControl key={ctrl.type} label={ctrl.label}></BuildControl></div>);
});
}
export default BuildControls;
`enter image description here Eslint不允许从回调返回,否则其他错误。
答案 0 :(得分:0)
您在问题中输入的代码不正确。您忽略了eslint抱怨的障碍。问题是您自己在行上的左括号和右括号是围绕的代码,其中不包含函数表达式或const / let声明,这意味着没有实际的块被创建。
const BuildControls = () => {
{ // Beginning of lone block
controls.map((ctrl) => {
console.log("ctrl is:", ctrl.label, ctrl.type);
return (<div className="BuildControls"><BuildControl key={ctrl.type} label={ctrl.label}></BuildControl></div>);
});
} // End of lone block
}
export default BuildControls;