反应组件渲染中的对象迭代不起作用
Object iteration in react component render is not working
首先,我想告诉你,我对 React 开发很陌生。当我尝试使用迭代呈现选项卡时,出现以下错误。有人可以帮助我确定为什么这不起作用。语法有错吗
#实施
Line 76: Expected to return a value in function array-callback-return
Line 77: Expected an assignment or function call and instead saw an expression no-unused-expressions
render() {
const { classes,orderTabDataCollections } = this.props;
const { value } = this.state;
return (
<div className={classes.root}>
<AppBar position="static" color="default">
<Tabs
value={value}
onChange={this.handleChange}
indicatorColor="primary"
textColor="primary"
variant="scrollable"
scrollButtons="auto"
>
{Object.keys(orderTabDataCollections).map(keyz =>
<Tab key={keyz} label={keyz.toUpperCase()} />
)}
</Tabs>
</AppBar>
{
Object.keys(this.props.orderTabDataCollections).map(function(keyz, index) {
value === index && <TabContainer key={keyz} >
<TweakDataForm key={keyz} tweakDataCollection={orderTabDataCollections[keyz]}/></TabContainer> })}
</div>
);
}
....
{
Object.keys(this.props.orderTabDataCollections).map(function(keyz, index) {
if(value === index){
return <TabContainer key={keyz} >
<TweakDataForm key={keyz} tweakDataCollection=
{orderTabDataCollections[keyz]}/>
</TabContainer>
}
return null;
})}
如果传递了回调函数,map
应该 return 来自其回调的一些值。像上面那样更新 map
包装 TabContainer
的代码应该可以修复 Line 76: Expected to return a value in function
错误。
首先,我想告诉你,我对 React 开发很陌生。当我尝试使用迭代呈现选项卡时,出现以下错误。有人可以帮助我确定为什么这不起作用。语法有错吗
#实施
Line 76: Expected to return a value in function array-callback-return
Line 77: Expected an assignment or function call and instead saw an expression no-unused-expressions
render() {
const { classes,orderTabDataCollections } = this.props;
const { value } = this.state;
return (
<div className={classes.root}>
<AppBar position="static" color="default">
<Tabs
value={value}
onChange={this.handleChange}
indicatorColor="primary"
textColor="primary"
variant="scrollable"
scrollButtons="auto"
>
{Object.keys(orderTabDataCollections).map(keyz =>
<Tab key={keyz} label={keyz.toUpperCase()} />
)}
</Tabs>
</AppBar>
{
Object.keys(this.props.orderTabDataCollections).map(function(keyz, index) {
value === index && <TabContainer key={keyz} >
<TweakDataForm key={keyz} tweakDataCollection={orderTabDataCollections[keyz]}/></TabContainer> })}
</div>
);
}
....
{
Object.keys(this.props.orderTabDataCollections).map(function(keyz, index) {
if(value === index){
return <TabContainer key={keyz} >
<TweakDataForm key={keyz} tweakDataCollection=
{orderTabDataCollections[keyz]}/>
</TabContainer>
}
return null;
})}
如果传递了回调函数,map
应该 return 来自其回调的一些值。像上面那样更新 map
包装 TabContainer
的代码应该可以修复 Line 76: Expected to return a value in function
错误。