Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda