question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date does not change (from default date)

See original GitHub issue

Hi, I’m trying to set the state of a component with datepicker from a parent component. But the date or input never change from the default moment() date after clicking on another date on the picker, manual input with keyboard (it goes back to default onBlur), etc. The state does not change either according to React Console. Please note that the Placeholder Text is not showing either. Here is my code:

Parent Component:

constructor(props) {
    super(props);

    this.state = {
      wants_interview_date: moment(),
  }
}

handleDateChange(date) {
    return (evt) => this.setState({ wants_interview_date: date });
 }

return <ChildComponent
        wants_interview_date={this.state.wants_interview_date}
        onDateChange={this.handleDateChange} />;

Child Component:

<DatePicker
  selected={this.props.wants_interview_date}
  onChange={this.props.onDateChange}
  className="form-control"
  id="wants_interview_date"
  placeholderText="Choose a Date"
/>

I am using Create-React-App if that makes a difference. Any ideas or tips are welcome (ASAP!).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
rafeememoncommented, Aug 6, 2017

In addition to binding the callback to the component, in the provided code, handleDateChange is returning an anonymous function that is never invoked; setState should be the only thing in the callback.

1reaction
andrewwong97commented, Aug 6, 2017
return <ChildComponent
        wants_interview_date={this.state.wants_interview_date}
        onDateChange={(date) => this.setState({wants_interview_date: date})} />;
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Excel Dates That Won't Change Format - Contextures
How to fix Excel dates that will not change format. Fix dates that end up in the wrong order when sorted. Use built-in...
Read more >
Change the date system, format, or two-digit year interpretation
But formatting dates so that they are easy to understand is equally important to ensuring ... Change the default date format to display...
Read more >
Change the default Date format in Excel
Change the default Date format · Step 1: Open the Regional setting · Step 2: Select another date format · Step 3: Change...
Read more >
How to change Excel date format and create custom formatting
If you want to set a different default date and/or time formats on your computer, for example change the USA date format to...
Read more >
Setting a Default Date Format in Excel - Causal
Once you've decided on the format, you need to go into the Excel options and select the 'Advanced' tab. In the 'Advanced' tab,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found