Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
React-hook-form `register` not registering field with name has a single quote in the middle,

I have integrated react-hook-form with my form, where it is not registering field with name has single quote in the middle. Instead it stripes single quote .

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);

output : {register Patients Name: undefined, gender: "female"}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It looks like you are trying to assign the input field name as the value. You could try using the 'name' as the field name and ${name} as the input value.

Something like this may work better:

  <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>

If you really need a dynamic input field name, you could try:

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda