0

CODE:

var Game = createReactClass({

    getInitalState() {
        return {
            start: false
        }                    
    },

    handleStartClick() {
        this.setState({
            start: true
        })
    },

    handleStopClick() {
        this.setState({
            start: false
        })
    },

    render() {
        return (
            <div>
                <h1>React.js Game of Life</h1>
                <div className="buttons">
                    <button className="btn btn-danger" onClick={this.handelStopClick}>Stop</button>
                    <button className="btn btn-success" onClick={this.handelStartClick}>Start</button>
                </div>
                <Board start={this.state.start}/>
            </div>
        )
    }

});

QUESTION:

Here is the error I get:

Cannot read property 'start' of null

If I change this.state.start to this.props.start, the error goes away but the board does not render.

How can I resolve this situation ?

2 Answers 2

3

Issue is, you have a spelling mistake, Instead of getInitalState use getInitialState, that's why, you are getting that error:

Cannot read property 'start' of null

Use this, it will work:

getInitialState() {
    return {
        start: false
    }                    
},
Sign up to request clarification or add additional context in comments.

Comments

0

Your state object is null. This is because you have typo in your function name. The function name should be getInitialState. Then your state would have the default value of start:false

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.