​ Handling Events

יצירת פונקציה שמטפלת ב event
והעברת פרמטרים state בעזרת arrow function


import React, { Component } from 'react';
class Counter extends Component {
    state = {
        count: 1
    };

    handle = product => {
        console.log(product);
        this.setState({count: this.state.count + 1})
    }

    render() { 
        return (
            <div>
                <div>{this.state.count}</div>
                <button 
                    onClick={() => this.handle({id:1})}
                    style={{fontSize: 10}} 
                    className="badge badge-secondary  btm-sm"
                >Increment </button>
            </div>
        );
    }

}
 
export default Counter;

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *