Button click not working in ReactJs

Button don't work

class ContactList extends Component {


    addTrack() {
        console.log('addtrack');
    }

    render(){
        console.log('addtrackssss');

        return (
            <div>
                <input type="text" ></input>
                    <button onclick={this.addTrack.bind(this)}>Add Track</button>

            </div>
        );
    }
}

Where my mistake. Do all like in this video https://www.youtube.com/watch?v=3FwoKdOMaFI

Upvotes: 0

Views: 1183

Answers (3)

Sivadass N
Sivadass N

Reputation: 927

Handling events with React elements is very similar to handling events on DOM elements. But one of the difference is React events are named using camelCase, rather than lowercase.

//Regular Javascript:
<button onclick="doSomeThing()">
  Click me!
</button>

//React:
<button onClick={doSomeThing}>
  Click me!
</button>

Upvotes: 0

Jagadish Upadhyay
Jagadish Upadhyay

Reputation: 1264

please change onclick to onClick

Upvotes: 2

Chris
Chris

Reputation: 58182

onclick should be onClick

Short answer, but its just a typo

Upvotes: 3

Related Questions