1

I have an if-else-block in my render-function. I always get the error that my myattribute is an unresolved variable.

render: function() {
    return ({
        this.state.something.length ? (
             <h3>Selected products</h3>
             <Element myattribute={this.state.something}/>
        ) : ''
    })
}
0

1 Answer 1

1

Reason is, you are returning more than one element if the condition is true, try this:

render() {
 return (
    <div>
      {
        this.state.something.length ? 
          <div>
             <h3>Selected products</h3>
             <Element myattribute={this.state.something}/>
          </div>
       : ''
      }
    </div>
  )
}
Sign up to request clarification or add additional context in comments.

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.