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

141
Vistas
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 Respuestas
Responde la pregunta

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