Languages
[Edit]
EN

React - open file input dialog box on custom button click

0 points
Created by:
Wesley
501

In this article, we would like to show you how to open file input dialog box on button click in React.

To open a file input box on button click, we use a simple trick:

  1. create invisible file input,
  2. use useRef() hook to create reference and assign it to the ref property of the invisible input,
  3. create a function that simulates the click on the invisible input using the reference,
  4. assign the function to the onClick property of the button.

Practical example

Edit

 

Alternative titles

  1. React - open file input dialog box on another element click
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join