Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React: why can't I update classes

So I was trying to use this 3 titles as tabs, changing the color of the selected one, however the state is changing correctly but the color is not changing because the classes are also not changing.Tabs

state

Debug output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Methods:

    setTabClass(tab) {
        console.log(this.graphTab);
        if (tab === this.graphTab) {
            return 'currentTab';
        }
        else {
            return '';
        }
    }

    handleClassClick = (tab) => {
        this.setState( {graphTab: tab} );
    }

Elements:

                    <div className='chart-area'>
                        <div className='chart-area-tabs'>
                            <p className={this.setTabClass('sales')} onClick={() => this.handleClassClick('sales')} >Sales (0$)</p>
                            <p className={this.setTabClass('order')} onClick={() => this.handleClassClick('order')} >Order Volume (0)</p>
                            <p className={this.setTabClass('ticket')}  >Ticket Size ($0.00)</p>
                        </div>
                    </div>

Can someone help me with this?

>Solution :

You’re reading the graphTab state wrong – it should be this.state.graphTab instead of this.graphTab in the setTabClass method.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading