In the component there is such a button:
<a href="#" className="controls-header-left" name="previous_year" onClick={this.previousControlClick}> <span className="glyphicon glyphicon-triangle-left" aria-hidden="true"> </span> </a> This button will scroll through the calendar a year ago. There is also a button that will translate year 1 forward. I want to do the same with the months and create 2 universal methods that, depending on the button name, will scroll through the month and year. In the general form, the scheme is the following: the method gets the name, proceeding from the name, goes to the desired case , then pulls the parent method, into which it reports what has changed. In the parent method, setState occurs. When clicked event.target.name is undefined . Accordingly, nothing changes further. Please tell me why this is happening and how to fix it.
The method at the moment is:
previousControlClick(event) { switch(event.target.name) { case 'previous_year' : { var changed_year = {'year': this.props.year-1} this.props.updateCalendar(changed_year) } case 'previous_month' : { } } } parent setState:
updateCalendar(param) { if(param.year !== 'undefined'){ this.setState({ year: param.year }) } else { this.setState({ year: param.month }) } }