title: Indeterminate checkbox in React JSX
body: <p>How do I render an indeterminate checkbox via JSX?</p>
  
  <p>Here's what I've tried:</p>
  
  <pre><code>function ICB({what}) {
    return &lt;input type="checkbox"
                  checked={what === "checked"} 
                  indeterminate={what === "indeterminate"} /&gt;;
  }
  </code></pre>
  
  <p>However, <code>indeterminate</code> is not an attribute on the <code>HTMLElement</code>, but a <strong>property</strong>. How do I set properties from React / JSX?</p>
  
  <hr>
  
  <p><strong><em>Solution</em></strong>:</p>
  
  <p>As most of the answers below use <code>findDOMNode</code> or <code>string</code> refs, both of which are no longer considered good practice in React, I've written a more modern implementation:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function ICB() {
    const [state, setState] = React.useState(0);
    const indetSetter = React.useCallback(el =&gt; {
      if (el &amp;&amp; state === 2) {
        el.indeterminate = true;
      }
    }, [state]);
    const advance = () =&gt; setState(prev =&gt; (prev + 1) % 3);
    
    return &lt;input type="checkbox"
                  checked={state === 1}
                  ref={indetSetter}
                  onClick={advance} /&gt;;
  }
                  
  ReactDOM.render(&lt;ICB /&gt;, document.getElementById("out"));</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="out"&gt;&lt;/div&gt;
  
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.production.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>