0

I was trying to debug a sidebar for a project I'm making. One of the sidebar buttons don't trigger the onClick event I specified. I was looking 30 minutes into the code, even went as far as to duplicate it and remove any unneccessary elements in order to debug it. My conclusion was:

  1. One of the buttons that I already had works properly and the other one I'm trying to fix doesn't even though they share the exact same code.
  2. Why is it behaving that way, is beyond me.

Can you find out why?

This is the cursed code:

import React from "react";

class SidebarTest extends React.Component {
    constructor() {
        super();
        this.state = {
            isDropdownActiveFlowers: false
        };
    }

    displayDropdownFlowers = () => {
        this.setState({
            isDropdownActiveFlowers: !this.state.isDropdownActiveFlowers
        });
        
        console.log(this.state.isDropdownActiveFlowers);
    };

    render() {
        return (
            <div className="sidenav">
                <h1 className="Sidebar-Name">Flooo</h1>

                <button onClick={this.displayDropdownFlowers}>works</button>
                <button onClick={this.displayDropdownFlowers}>works</button>
                <button onClick={this.displayDropdownFlowers}>works</button>
                <button onclick={this.displayDropdownFlowers}>doesnt work</button>
                <button onclick={this.displayDropdownFlowers}>doesnt work</button>
            </div>
        );
    }
}

export default SidebarTest;
1
  • onclick and onClick Commented Apr 4, 2021 at 11:44

1 Answer 1

6

I think you are using "onclick" instead of "onClick"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.