0

I have this code here inside the return section in React-

this.state.paymentoptions.map((x)=>(
                                    <div><button style={{marginLeft:'10px'}}>{if(x.method!=online){x.method}}</button><br></br></div>
                                ))

Here I am trying to use if inside the map. But its giving me Unexpected token. How to fix this?

hearty
  • 691
  • 5
  • 10
  • 15

1 Answers1

0

The if inside the JSX is the problem. You can't do it like that. This should work.

this.state.paymentoptions.map((x)=>(
          <div>
            <button style={{marginLeft:'10px'}}>
              {x.method !== online ? x.method : null}
            </button><br></br>
          </div>
        ))
Rodius
  • 2,271
  • 14
  • 19