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.

Provide a simple moment-less API

See original GitHub issue

In one of my projects I’m passing dates to server API calls as strings, and I also receive dates back as strings which are stored in redux state. In the spirit of keeping my state clean I keep the strings as the source of truth rather than moment objects; this also makes it possible to pre-generate my state on the server, which would get ugly if it contained moment objects. This led me to write a wrapper datepicker component that would simply translate between strings and moment objects so that they can be passed as props to the datepicker. This got me thinking that maybe we should provide a way of dealing with strings natively in this component. I can think of a couple approaches here:

  1. Provide wrapper component in datepicker – Only functionality would be to wrap/unwrap moment objects and pass them to the real datepicker component. Probably the easiest to maintain, cleanest code-wise; but calling something SimpleDatePicker seems a little silly
  2. Provide a simple prop – When set all props (selected, minDate, etc, the value passed to onChange) will be strings formatted according to dateFormat. A little dirtier code-wise; adding a prop to control how other props are handled seems kind of anti-react to me
  3. Automatically determine behavior – Determine the intended behavior by what is passed into selected: if a string, everything is a string, and if a moment, everything is a moment. By far the simplest API; dirtier code-wise, and I’m not sure how it should behave when selected is null

What does everyone think?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

14reactions
greabercommented, Jul 25, 2016

IMO, since a date picker just lets you choose a year, month, and day, its state should just be three JavaScript numbers. The component is just a piece of UI and shouldn’t be prescriptive about your data model. It shouldn’t require a heavy dependency like moment.js or even use JavaScript dates. You can keep whatever you want in Redux – triples of numbers, JavaScript dates, moment dates, or even strings. Also, instead of adding timezone awareness as suggested in #507 and #498, it could just allow the user to explicitly pass a value for “today” (which would also be a triple of numbers).

3reactions
martijnrusschencommented, Mar 4, 2016
  1. Feels silly but keeps it simple
  2. Sounds nice, but feels wrong.
  3. This is probably the best UX, but I don’t think this is really stable and reliable in the future.

This comment isn’t really helping, but wanted to share my thoughts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use An API (The Complete Guide) [Simple ... - RapidAPI
Let's take for example the Numbers API. This is a simple and free API providing interesting information about numbers and dates.
Read more >
How to do a greater than or equal to with moments (moment.js ...
Basically, I want to do a myMoment >= yourMoment . There is no myMoment.isSameOrAfter and writing that out combining isSame and .isAfter is...
Read more >
MySchool Features & Capabilities - GetApp
API. Access Controls/Permissions. Activity Dashboard. Activity Tracking ... Screenshots. MySchool screenshot: A powerful, all-in-one, simple to use, ...
Read more >
Understand Backbone Forms and Backbone.Model's Two/Way Data ...
This step demonstrates how Backbone Forms produces simple, clean JSON objects ... Task 3: Generate a VersionOne API/compatible JSON DTO using the Editor....
Read more >
Mathematical model of a moment-less arch - Semantic Scholar
... of arch self-weight and the ability to produce moment-less arch forms ... Simple innovative comparison of costs between tied-arch bridge ...
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