0

Here is their sample component.

class MyAwesomeComponent extends React.Component {
  state = {
    selectedDay: new Date(),
  };
  handleDayClick = day => {
    this.setState({
      selectedDay: day,
    });
  };
  render() {
    return (
      <div>
        <DayPicker
          onDayClick={this.handleDayClick}
          selectedDays={this.state.selectedDay}
        />
      </div>
    );
  }
}

How do you get the selected data from this sample react component?

user2355785
  • 251
  • 1
  • 3
  • 4

1 Answers1

1

this.state.selectedDay will have your selected date after the selection complete.

bennygenel
  • 23,896
  • 6
  • 65
  • 78
  • this.state.selectedDay is in the context of DayPicker not my parent component. I don't have access to DayPicker's state. – user2355785 Aug 30 '17 at 10:39
  • on `handleDayClick = (day) => {...} ` you are setting the selected day to your states selectedDay. – bennygenel Aug 30 '17 at 10:43
  • this.state.selectedDay is undefined in parent component. My solution was to pass a callback function into the component and return the value through the callback. – user2355785 Aug 30 '17 at 14:04
  • then I think this is not your actual code. Can you paste your actual code please – bennygenel Aug 30 '17 at 18:10