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

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

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