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

162
Views
How to update the values of Multiple Components in React JS?

My react project name is "counter-app" and it has multiple components, I want to update the values of every counter button but at that instance there is a problem arise

Code snippet of Counter.jsx:

import React, { Component } from 'react';

class Counter extends Component {
    state = {
        count : 0
    };

    handleIncrement = product => {
      console.log(product);
      this.setState({ count : this.state.count + 1 }); 
    };

    render() { 
        return (
         <div>
            <span className={this.getBadgeClasses()}>{this.formatCount()}</span>
            <button 
             onClick={() => this.handleIncrement(product)} 
             className="btn btn-secondary btn-sm"
            >
                Increment
            </button>
        </div>
        );
    }
    
    getBadgeClasses() {
        let classes = "badge m-2 badge-";
        classes += this.state.count === 0 ? "warning" : "primary";
        return classes;
    }

    formatCount(){
        const {count} = this.state;
        return count === 0 ? "Zero" : count;
    }
}
 
export default Counter;
about 4 years ago · Santiago Trujillo
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!