import React, {Component} from 'react';

interface Buggy2State {
    clicked: boolean
}

class Buggy2 extends Component<{}, Buggy2State> {

    constructor(props: {}) {
        super(props);
        this.state = {
            clicked: false
        };
    }

    handleClick = () => {
        // This next line is commented out because it breaks the build, since it's invalid code.
        // You can uncomment it to see the compiler error.
        // this.state.clicked = true; // <- TypeScript is actually finding our bug for us here!
        console.log("Clicked!");
    };

    render() {
        let message;
        if (this.state.clicked) {
            message = "I've been clicked!";
        } else {
            message = "Click me!";
        }

        return (
            <div>
                <p>{message}</p>
                <button onClick={this.handleClick}>Click Here</button>
            </div>
        );
    }

}

export default Buggy2;
