Uncaught Error: Failed to get month from date: 2020-09-22T05:00:00.000Z.
See original GitHub issueI 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:
- Created 3 years ago
- Reactions:4
- Comments:9 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ended up doing the following:
<DatePicker value={typeof value === "string" ? new Date(value) : value} />
Pass value as Date, not as string. This will fix the issue.