0

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 | )}}

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

  {!loading&&documents.length>0?(
   documents.map((item, i) => {
    return (
    <ViewButton>mybutton</ViewButton>
    )}

   )):(
   null
 )}
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.