title: How do I conditionally add attributes to React components?
body: <p>Is there a way to only add attributes to a React component if a certain condition is met?</p>
  <p>I'm supposed to add required and readOnly attributes to form elements based on an Ajax call after render, but I can't see how to solve this since <code>readOnly=&quot;false&quot;</code> is not the same as omitting the attribute completely.</p>
  <p>The example below should explain what I want, but it doesn't work.</p>
  <blockquote>
  <p>(Parse Error: Unexpected identifier)</p>
  </blockquote>
  <pre class="lang-js prettyprint-override"><code>function MyInput({isRequired}) {
    return &lt;input classname=&quot;foo&quot; {isRequired ? &quot;required&quot; : &quot;&quot;} /&gt;
  }
  </code></pre>