Skip to content

Typo for onClick prop for Square class component in Tutorial #2817

@pnaranja

Description

@pnaranja

In https://reactjs.org/tutorial/tutorial.html#lifting-state-up

It mentions changing the Square component to
class Square extends React.Component { render() { return ( <button className="square" onClick={() => this.props.onClick()} > {this.props.value} </button> ); } }

But this results in the page error:

Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

To fix this, I had to change the onClick to:
onClick={() => this.props.onClick}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions