Reputation: 7768
I was trying to implement array iteration inside a conditional statement in react native like this,
{!loading&&documents.length>0?(
{documents.map((item, i) => {
return (
<ViewButton>mybutton</ViewButton>
)}}
):(
null
)}
But it shows syntax error in console
Unexpected token, expected "," (43:21)
41 | 42 |
{!loading&&documents.length>0?(43 | {documents.map((item, i) => { | ^ 44 | return ( 45 | sss 46 | )}}
Upvotes: 0
Views: 37
Reputation: 5460
Try this
{!loading&&documents.length>0?(
documents.map((item, i) => {
return (
<ViewButton>mybutton</ViewButton>
)}
)):(
null
)}
}
Upvotes: 0
Reputation: 176
You have a syntax issue, this should work:
!loading && documents.length > 0
? documents.map((item, i) => {
return <ViewButton>mybutton</ViewButton>;
})
: null;
I'd highly recommend to use a linter (eslint) and something like prettier so you don't run in issues like these.
Upvotes: 2