Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Date Picker Error

Bart Cernel free asked 5 years ago


I'm having issues with the DatePicker component. On my machine, everything seems to work fine. I can tell the issue is with the 'value' param on the component. I'm using a ternary to set the date but when I use 'new Date(value)' it crashes on other peoples machines on my team. We are all using windows 10 machines but it only works properly on mine.

DatePicker

format='MM-DD-YYYY'

keyboard

value={this.state.endDate != null ? new Date(this.state.endDate) : null}

getValue={ (evt) => this.setState({endDate: evt})}

label="End Date"


Jakub Mandra staff answered 5 years ago


Hi,

I think it is because you're building new Date() object - it's a mutation. The datePicker gets updated and the getValue function is then executed. This causes infinite loop of updates.

I suggest to set your date in state

  state = {
    endDate: new Date("12.12.2012")
  }

Best,

Jakub



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.8.4
  • Device: Laptop
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No
Tags