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

130
Views
React-hook-form `registrar` que no registra el campo con el nombre tiene una comilla simple en el medio,

He integrado react-hook-form con mi formulario, donde no está registrando el campo con el nombre tiene una comilla simple en el medio. En su lugar, se divide entre comillas simples.

 import React from "react"; import ReactDOM from "react-dom"; import { useForm } from "react-hook-form"; import "./styles.css"; //App component export default function App() { const { register, handleSubmit } = useForm(); //onSubmit Handler const onSubmit = (data) => console.log(data); //field name value const name = "Patient's Name"; //Return return ( <form onSubmit={handleSubmit(onSubmit)}> <input {...register(`register ${name}`)} /> <select {...register("gender")}> <option value="female">female</option> <option value="male">male</option> <option value="other">other</option> </select> <input type="submit" /> </form> ); } //Renders const rootElement = document.getElementById("root"); ReactDOM.render(<App />, rootElement);

salida: {registrar nombre de pacientes: indefinido, género: "femenino"}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que está intentando asignar el nombre del campo de entrada como valor. Podría intentar usar el 'nombre' como el nombre del campo y ${name} como el valor de entrada.

Algo como esto puede funcionar mejor:

 <form onSubmit={handleSubmit(onSubmit)}> <input {...register("name")} /> <select {...register("gender")}> <option value="female">female</option> <option value="male">male</option> <option value="other">other</option> </select> <input type="submit" /> </form>

Si realmente necesita un nombre de campo de entrada dinámico, puede intentar:

 const name = "Patient\'s Name"; return ( <form onSubmit={handleSubmit(onSubmit)}> <input {...register({name})} /> <select {...register("gender")}> <option value="female">female</option> <option value="male">male</option> <option value="other">other</option> </select> <input type="submit" /> </form> ); }
about 4 years ago · Juan Pablo Isaza 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!