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

react向组件传递函数方式 #29

Open
Clearives opened this issue Mar 28, 2020 · 0 comments
Open

react向组件传递函数方式 #29

Clearives opened this issue Mar 28, 2020 · 0 comments
Labels

Comments

@Clearives
Copy link
Owner

react向组件传递函数方式

bind

constructor(props) {
super(props);
this.state = {
  value: 0
};
this.handleClick2 = this.handleClick1.bind(this);
}

箭头函数

handleClick3 = () => {
  console.log(this);
};

直接传递

handleClick1() {
  console.log(this);
}
<button onClick={this.handleClick1}>click 1</button>
<button onClick={this.handleClick2}>click 2</button>
<button onClick={this.handleClick3}>click 3</button>

点击三个按钮输出结果如下图:
GkrOxI.png

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

No branches or pull requests

1 participant