How to trigger INPUT FILE event REACTJS by another DOM

后端 未结 6 992
-上瘾入骨i
-上瘾入骨i 2021-01-02 01:53

I have a INPUT BUTTON and INPUT FILE, I want to click the BUTTON and it will trigger the INPUT FILE event

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 02:26

    You could trigger the input type file with ref, f.e:

    on your class component:

     this.fileInput = fileInput} 
        type="file"
     />
    
    

    and make a function on that class component too:

    triggerInputFile = () => this.fileInput.click()
    

提交回复
热议问题