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

166
Views
ReactJs, almacenando entradas de usuario como un nuevo objeto en una matriz vacía

Estoy tratando de almacenar en una matriz vacía una entrada de usuario y una identificación única como objeto.

Así que tengo:

 const [weight, setWeight] = useState([]);

que quiero llenar con esta función:

 const submitWeight = () => { setWeight([{ value: inputWeight, id: uuidv4() }, ...weight]); // this one. setDefaultMessageWeight(""); closedClass(); };

¿Algunas ideas? ¡Gracias!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Aquí hay un ejemplo de cómo puede acceder a un elemento de entrada renderizado usando ref dentro de su componente.

 import { useRef, useState } from "react"; export default function App() { const [weight, setWeight] = useState([]); const inputRef = useRef(null); const submitWeight = () => { let inputWeight = inputRef.current.value; setWeight([{ value: inputWeight, id: uuidv4() }, ...weight]); // ... }; return ( <div> <input ref={inputRef} /> <button onClick={submitWeight}>Submit</button> {weight.map(({ value }, index) => ( <p> Weight #{index} is {value} </p> ))} </div> ); }
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!