#reactjs
#reactjs
Вопрос:
Я создаю средство загрузки файлов с помощью react. Я хочу скрыть элемент ввода файла по умолчанию и активировать его, когда пользователь нажимает на div.
<div style={{position:"relative",width:"500px",height:"300px",background:"gray",marginLeft:"auto",marginRight:"auto",border:"2px
dotted white"}}
onClick={this.clickOnFakeUploader}
>
<div style={{float:"left",marginTop:"100px",width:"100%"}}>
<h4 style={{color:"white",marginLeft:"auto",marginRight:"auto"}}>Drag amp; Drop Files Here!
</h4>
</div>
</div>
<label className="btn btn-default" style={{display:"none"}}>
<input ref={this.fileUploader} type="file" multiple onChange={this.selectFiles} />
</label>
this.fileUploader = React.createRef();
this.clickOnFakeUploader = () =>{
this.fileUploader.click();
}
Я получаю TypeError: this.fileUploader.click is not a function
сообщение об ошибке.
Ответ №1:
this.fileUploader.current.click()
вам нужно обратиться к нему с помощью current