Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!