Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bizarre warnings when adding onClick handler to button #68

Closed
jeghers opened this issue May 31, 2017 · 2 comments
Closed

Bizarre warnings when adding onClick handler to button #68

jeghers opened this issue May 31, 2017 · 2 comments

Comments

@jeghers
Copy link

jeghers commented May 31, 2017

After adding a click handler to a button, these warnings now fill the console with every click:

Warning: isMounted(...) is deprecated in plain JavaScript React classes. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks.
Warning: replaceState(...) is deprecated in plain JavaScript React classes. Refactor your code to use setState instead (see facebook/react#3236).

Here is the render code:

onClick() {
console.log('onClick - this...');
console.log(this);
}

render() {
console.log('this.props.about...');
console.log(this.props.about);
return (



{this.renderUserList()}
<button onClick={() => this.onClick()}> Increment 
  Count is {this.props.about.counter}

);
}

(I was forced to use the arrow function for onClick in order to get a this pointer in the handler function)

@jeghers
Copy link
Author

jeghers commented May 31, 2017

Note: this happens in IE but not Chrome

@wellyshen
Copy link
Owner

wellyshen commented May 31, 2017

@jeghers

I guess onClick isn't the main reason for causing this warning. Have you used any out of updated 3rd party library or used the isMounted() method? See here for more information.

If I were you I will write the function as below :

handleOnClick = () => {
  console.log('onClick - this...');
  console.log(this);
}

render() {
  return <button onClick={this.handleOnClick} />;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants