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

145
Views
¿Cómo puedo acumular valores de cadena en useState como un valor de matriz en React?

Creé un valor llamado decrecimiento de LongitudImg con la matriz useState. Cuando se ejecuta la función deleteImgfunc, el valor se ingresa como un valor de cadena. si se ejecuta deleteImgfunc, el primero puede contener un valor de "error", si se ejecuta deleteImgfunc, la segunda vez puede aparecer el valor "pizza".

En este momento, quiero almacenar valores de cadena en degrowthLengthImg como una matriz.

como esta respuesta esperada

 degrowthLengthImg = ["buger", "pizza"]

así que hice mi código pero sale como un golpe

 degrowthLengthImg = ["b", "g", ....]

este es mi codigo

 const [degrowthLengthImg, setDegrowthLengthImg] = useState([]) const deleteImgfunc = useCallback((value: string) => { setDegrowthLengthImg([...degrowthLengthImg, value]); }, []); return( <Pressable style={farmDiaryViewWrapperStyle.imgcloseBtn} onPress={() => deleteImgfunc?.(v?.name)} > )

¿Cómo puedo arreglar mi código?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Use lo siguiente para agregar valor a la matriz. No utilice la función de inserción para insertar en una matriz. Además, useCallback es innecesario.

 const [degrowthLengthImg, setDegrowthLengthImg] = useState([]) const deleteImgfunc = useCallback((value: string) => { // If you want to add to array setDegrowthLengthImg(deg => [...deg, value]); }, []);
about 4 years ago · Santiago Trujillo Report

0

Debe usar setDegrowthLengthImg como,

 setDegrowthLengthImg(degrowthLengthImg => [...degrowthLengthImg, value]);
about 4 years ago · Santiago Trujillo Report
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!