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.

Uncaught Error: Failed to get month from date: 2020-09-22T05:00:00.000Z.

See original GitHub issue

I am using local storage to store some form data for caching between reloads. The date is stored into the local storage as 2020-09-25T05:00:00.000Z (local storage json {"hasValue":true,"processed":{"start":"2020-09-25T05:00:00.000Z"}} JSX <DatePicker minDate={new Date('2000-01-01')} format="M/d/yyyy" value={state.processed?.start} onChange={e => dispatch({ type: 'processedFrom', payload: e })} />

The initial load works but when trying to open the calendar by clicking on the input the following error is thrown

Uncaught Error: Failed to get month from date: 2020-09-25T05:00:00.000Z.
    at getMonth (index.js:64)
    at getDayStart (index.js:272)
    at index.js:21
    at Array.map (<anonymous>)
    at makeGetRangeInternal (index.js:20)
    at getRange (dates.js:269)
    at getTileClasses (utils.js:102)
    at TileGroup (TileGroup.js:41)
    at renderWithHooks (react-dom.development.js:14803)
    at mountIndeterminateComponent (react-dom.development.js:17482)
    at beginWork (react-dom.development.js:18596)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at beginWork$1 (react-dom.development.js:23203)
    at performUnitOfWork (react-dom.development.js:22154)
    at workLoopSync (react-dom.development.js:22130)
    at performSyncWorkOnRoot (react-dom.development.js:21756)
    at react-dom.development.js:11089
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11084)
    at flushSyncCallbackQueue (react-dom.development.js:11072)
    at discreteUpdates$1 (react-dom.development.js:21893)
    at discreteUpdates (react-dom.development.js:806)
    at dispatchDiscreteEvent (react-dom.development.js:4168)

Additional:

storage is handled by the following hook:

export const usePersistedReducer = (key, reducer, defaultValue)=> {
  const [state, dispatch] = useReducer(reducer, defaultValue, (val) => JSON.parse(localStorage.getItem(key)) || defaultValue);
  useEffect(() => {
    localStorage.setItem(key, JSON.stringify(state));
  }, [key, state]);
  return [state, dispatch];
}

when local storage is empty the component functions just fine till refresh tries to set the value as the moment string

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
philohelpcommented, Aug 16, 2021

I ended up doing the following: <DatePicker value={typeof value === "string" ? new Date(value) : value} />

5reactions
wojtekmajcommented, Mar 10, 2021

Pass value as Date, not as string. This will fix the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get only date and give only date as input to reat-date-picker
Someone help me out. Please refer to the sandbox link. Failed to get month from date: Reference: https://codesandbox ...
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