Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda