2

I'm using react-datePicker package in Formik and this error pops up initially rendering page

react-dom.development.js:23803 Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

referred this solution


<DatePicker
      {...field}
      {...props}
      selected={(field.value && new Date(field.value)) || null}  
      onChange={val => {
        setFieldValue(field.name, val);
      }}
    />

in my case the problem is initially field.value is NaN-NaN-NaN later its is fetched and set to yyyy-mm-dd.

How to validate NaN in selected={(field.value && new Date(field.value)) || null}

Hithesh kumar
  • 1,008
  • 9
  • 25

1 Answers1

1

Try to set initial field value with new Date(), helps for me

Maxim
  • 148
  • 6