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.

Date objects are converted to strings

See original GitHub issue

In the following scenario the Date() object is converted to a string after page refresh:

state: () => {
  items: []
}

actions: {
  addItem(data) {
    const newItem = data
    newItem.createdDt = new Date()
    this.items.push(newItem)
  }
}

When I add the item and retrieve it immediately, it is a Date object. However, after refreshing the page, when the store is restored from local storage items[0].createdDt is a string.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
prazdevscommented, Jan 24, 2022

I’ll add a line in the “limitations” part of the readme, specifying that serialization loses non primitive types such as Date. Workaround can also be the use of the freshly implemented hooks! 😃

Seems like a wont-fix with a workaround to me, if you’re fine with it.

0reactions
prazdevscommented, Jan 24, 2022

aa52a70 should close this. Thanks for the contribution!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert Date to String in Java - GeeksforGeeks
Get an instance of LocalDate from date. Convert the given date into a string using the toString() method of LocalDate class. Print the...
Read more >
Java Convert Date to String - javatpoint
Java Date to String Example · Date date = Calendar.getInstance().getTime(); · DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); · String strDate ...
Read more >
How to convert a JavaScript date object to a string?
The toISOString() method is used to convert the date object into the ISO string format. It is a built-in method of the Date...
Read more >
Date.parse() - JavaScript - MDN Web Docs
The parse() method takes a date string (such as "2011-10-10T14:48:00" ) and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC....
Read more >
JavaScript Date toString() Method - W3Schools
Every JavaScript object has a toString() method. The toString() method is used internally by JavaScript when an object needs to be displayed as...
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