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

133
Views
El componente React no se volverá a procesar en el cambio de estado

Aquí está mi código. La variable de estado de imageChunks no se actualiza correctamente. Seleccionar una imagen devuelve una matriz vacía. Seleccionar otra imagen devuelve una matriz de fragmentos base64 de la última imagen. Parece que setImageChunks() no activa una nueva representación. ¿Qué está causando esto? Cualquier ayuda sería apreciada.

 const [ imageChunks, setImageChunks ] = useState([]) const handleImageChange = async (e) => { const files = e.target.files // Break image base64 string into chunks for database upload, store each in object with series (filename) and part const getChunks = (filename, baseStr, chunkSize) => { const str = baseStr.split("") const chunks = [] let part = 0 let count = str.length let start = 0 while (count){ part++ start = str.length - count const allowedCount = count < chunkSize ? count : chunkSize chunks.push({ series: filename, part: part, data: str.slice(start, start + allowedCount).join("") }) count -= allowedCount } return chunks } // empty imageChunks array to prepare for new file selection const fileChunks = [] for (let i = 0; i < files.length; i++){ // Push file name to product object imageFiles array const fileNames = formValues.imageFiles fileNames.push(files[i].name) setFormValues({...formValues, imageFiles: fileNames}) // get array of file chunk objects, push to imageChunks array const file = await new Response(files[i]).arrayBuffer() const baseString = Buffer.from(file).toString('base64') const chunks = getChunks(files[i].name, baseString, 10000) fileChunks.push(chunks) } setImageChunks(null) setImageChunks([...fileChunks]) console.log(imageChunks) }
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!