JSX help in React.js

JSX help in React.js
0

#1

I am getting error (Syntax error: Unexpected token, expected } (16:78)) in below code.

                       render() { 
                    return (<tr key={this.props.index}>
                        <td>Name</td>
                        <td>
                        { 
                            this.props.element ? 
                            <input type="text"/> : this.props.element <span className="edit">                                                   
                            Edit</span>
                        }
                        </td>
                  </tr>
                    );
	            }

#2

What error?
The more info you will provide the better the help you’d get ^^


#3

replace element with this.props.element and remove () and {} around it.


#4

Thanks @Layer. I edited the code. Thanks.


#5

Thanks @jcunanan05. I followed your instruction but result is as before. I edited the code. Thanks.


#6

Try the following and see if it works for you.

render() { 
  return (
    <tr key={this.props.index}>
      <td>Name</td>
      <td>
        {
          this.props.element
            ? <input type="text" />
            : this.props.element (<span className="edit">Edit</span>)
        }
      </td>
    </tr>
  )
}

#7

I dont know if this part makes any sense…

So, you are using a intenary operator, cool there on if exists anything on this.props.element.

So, if it’s true, ok put the index

But if not, use this.props.element? I think there’s the error.