+ 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

1st Nov 2018, 3:13 PM
Sixface
Sixface - avatar
2 ответов
+ 3
<button onClick={this.handleClick}> Source: https://reactjs.org/docs/faq-functions.html
9th Nov 2018, 1:59 PM
Googel
Googel - avatar
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} /> } }
10th Nov 2018, 12:45 AM
Sergei No
Sergei No - avatar