+ 3
How to transfer Props in components to components using onclick function?
when i click button that time called function inside that function i passing props in reactjs
2 Antworten
+ 3
<button onClick={this.handleClick}>
Source:
https://reactjs.org/docs/faq-functions.html
0
Not good way (creates new function for each render)
const Button = (props) => <button onClick={() => props.handleClick(props)} />
Better
class Button extends Component{
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(){
// this props is available here
this.props.showSuper();
}
render(){
return <button onClick={this.handleClick} />
}
}