Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
How to set a state with a static file instead of a user input

I have a form that submits a file. Currently the user's input is used to set the state of a variable to a file; instead, I'd like to set the state to a hardcoded static file that I imported locally

This is the original code that sets the state using user input:

const [file, setFile] = useState(null);

const onSubmit = async (e) => { 
   //submit function
}


<form onSubmit={onSubmit}>
   <input
       type="file"
       onChange={(e) => setFile(e.target.files[0])}
   />
   <button>
      Submit!
   </button>
</form>

When testing is the state was set properly using console.log({file}), I will get a return with the file input...

But I want to get rid of the option to input a file and simply set the state with a static file... this is similar to what I tried:

import exampleFile from file/example.mp4;

const [file, setFile] = useState(null);

const onSubmit = async (e) => { 
   //submit function 
}

const handleClick = () => { 
   setFile({exampleFile}) 
}


<form onSubmit={onSubmit}>
   <button onClick={handleClick}>
      Submit!
   </button>
</form>
when I console.log the file, I get null... when testing if the file was set using console.log({file}), I get a null response

After quite a bit of digging, I have not been able to come up with any solid solutions. I'm stuck with this, so any help is greatly appreciated, thank you

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!