简体   繁体   中英

Saving moments to use as events in React-Big-Calendar

I'm having trouble generating events for react big calendar. When making a new event object (in another component), I set the id, event name, just fine, and then I wonder if I'm setting start and end correctly. I'll have a moment like this (created with moment.js) date = 05/15/2018 11:00 AM , and when setting the start/end fields of an event I will set them as new Date(date) . For now I am saving this value in local storage, but it eventually will go to a database. I checked, and when I create a constant at the top of my component with my moments, and the new Date() syntax explicitly in the code it works fine, but my pre-made saved dates are not working. I am getting the following error.

index.js:209 Uncaught TypeError: date[("get" + method)] is not a function
    at Object.hours (index.js:209)
    at Object.isJustDate (dates.js:91)
    at TimeGrid.js:237

My question is how should I go about saving my moment so that it can be correctly interpreted by react big calendar?

I answered my own question, Store `new Date ()` in JSON object

You can't store a Date as a Date in JSON, you have to convert it, so I will do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM