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

140
Visualizações
React: onClick function only console.logging is causing the whole page to refresh

I am very puzzled by this. I have a modal that opens up to allow a user to fill out information. I have an add button that adds a new row to store and renders a new row. But I realized that even if I am only console logging, clicking that button causes the whole page/tab to do a full refresh. Why is this happening? I was initially checking for props or state changes but cannot figure it out.

handleAddNewRow = () => {
   console.log('adding new row')
   // this.setState(...) -- this is commented out due to make sure that setting state is not the problem
}

<FormSection>
   {this.state.stores.map(store, index) => (
      <div key={store.id}>
         <div>
            <h4>
               Choose Store
            </h4>
            <Dropdown options={storeOptions}>
            </Dropdown>
         </div>
         <TextInput />
         <TextInput />
      </div>
   )}
   <div>
      <button onClick={this.handleAddNewStore}>
         Add New Store
      </button> 
   </div>
</FormSection>

I thought that the setting state was the issue but I commented that out. I tried wrapping the component in a React.memo() as well. Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It probably causes form sending. You should pass in your onClick callback event parameter and call event.preventDefault() method.

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