/ / Come posso impostare l'autofocus su un ingresso che reagisce è il rendering: html, reactjs, autofocus

Come posso impostare l'autofocus su un ingresso che reagisce è il rendering: html, reactjs, autofocus

Quando imposto l'attributo autofocus su un ingresso I "m di ritorno da una classe react viene generato il seguente errore:

 error TS2339: Property "autofocus" does not exist on type "HTMLAttributes"

Questo è il codice offendente:

return <input type="text" onChange={this.handleChange} value={this.state.text} autofocus/>;

Ho provato più verboso autofocus="autofocus" senza fortuna.

Questo può essere fatto usando react e html? Potrei impostarlo con javascript ma preferirei una soluzione html se ne esiste una.

(Modificare) Come sottolineato da Dominic Tobias, autoFocus (case sensitive) da solo fa il trucco, se si tenta di impostare la proprietà in questo modo autoFocus="autofocus" otterrai l'errore:

TS2322  Type "string" is not assignable to type "boolean".

risposte:

4 per risposta № 1

Reagisci a casi di cammello attributi. Uso:

 <input type="text" onChange={this.handleChange} value={this.state.text} autoFocus />;