admin管理员组文章数量:1336660
Having a slight issue with some code that I have written, I keep getting the error:
expected an assignment or function call and instead saw an expression
I have mented where the error is happening. Not sure what the issue is however. Code is as follows:
renderBody() {
const { bookings } = this.props;
if (bookings.length > 0) {
return (
Object.keys(bookings).map(e => (
<TableBody>
{Object.values(bookings[e]).forEach((value) => {
<TableCell>{value}</TableCell>; //<-ERROR??
})}
</TableBody>
))
);
}
return null;
}
Having a slight issue with some code that I have written, I keep getting the error:
expected an assignment or function call and instead saw an expression
I have mented where the error is happening. Not sure what the issue is however. Code is as follows:
renderBody() {
const { bookings } = this.props;
if (bookings.length > 0) {
return (
Object.keys(bookings).map(e => (
<TableBody>
{Object.values(bookings[e]).forEach((value) => {
<TableCell>{value}</TableCell>; //<-ERROR??
})}
</TableBody>
))
);
}
return null;
}
Share
Improve this question
edited Apr 18, 2018 at 14:01
Mayank Shukla
105k19 gold badges162 silver badges145 bronze badges
asked Apr 18, 2018 at 13:45
RazielRaziel
1,5662 gold badges17 silver badges36 bronze badges
3
- Are you using curlys there where you should be using parenths to return implicitly? – sesamechicken Commented Apr 18, 2018 at 13:47
-
Please update your question with a minimal reproducible example demonstrating the problem, ideally a runnable one using Stack Snippets (the
[<>]
toolbar button). Stack Snippets support React, including JSX; here's how to do one. – T.J. Crowder Commented Apr 18, 2018 at 13:52 -
Maybe not supporting a destructuring assignment? Try removing
const {bookings}
– Jonas Wilms Commented Apr 18, 2018 at 13:54
3 Answers
Reset to default 4Because you are not doing anything inside forEach
(no assignment, no calculation), also forEach
will not return anything, use map
to return the TableCell for each array entry.
Eslint
will throw an error, if you write a forEach
loop without any operation.
Write it like this:
{Object.values(bookings[e]).map(value => (
<TableCell>{value}</TableCell>
))}
You are just missing a closing )
:
Object.values(bookings[e]).map(value => (
<TableCell>{value}</TableCell>
))} // <--
Try to use normal for loop instead of map or forEach if you want to process some data inside the loop.
If you are returning an HTML content then you should explicitly return it.
Object.keys(bookings).map(e => {
return (
<TableBody>
{Object.values(bookings[e]).forEach((value) => {
return (
<TableCell>{value}</TableCell>
)
})}
</TableBody>
)
})
本文标签: javascriptExpected an assignment or function call and instead saw an expression errorStack Overflow
版权声明:本文标题:javascript - Expected an assignment or function call and instead saw an expression error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742421818a2471810.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论