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

173
Vistas
What do round brackets mean here? React Hook Form

Here is a custom input component

const Input = ({props}) => {
    return (
        <input type="text" {...props} {...props.reg}/>
    );
};

I passed a React Hook Form register function to this custom Input.

        <Input props={{
            placeholder: 'Name',
            id: 'form__name',
            name: 'name',
            reg: {...(register('name'), {required: true})}
        }}/>

Input was registered and I was not able to figure out what do round brackets before the spread operator mean.

What kind of JS/React syntax is it? ...(xxx, xxx)

P.S. this line of code

reg: {...(register('name'), {required: true})}

was taken from some youtube video, I just rewrote it, but round brackets before spread operator were still used in the video

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

The comma operator is rarely used in this way but essentially, if you do this

statment1, statement2

Then the second statement is returned. However, statment1 is executed, just not returned.

Here its used to register the field but the result of the statement inside the brackets is actually just {required: true}.

The brackets themselves just enclose this inner comma statement. The inside of the brackets is evaluated first, and the result of that is then spread.

More info here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator

about 4 years ago · Santiago Gelvez 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