Provide a simple moment-less API
See original GitHub issueIn 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:
- 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 - Provide a
simple
prop – When set all props (selected
,minDate
, etc, the value passed toonChange
) will be strings formatted according todateFormat
. A little dirtier code-wise; adding a prop to control how other props are handled seems kind of anti-react to me - 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 whenselected
isnull
What does everyone think?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:8 (5 by maintainers)
Top 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 >
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 Free
Top 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
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).This comment isn’t really helping, but wanted to share my thoughts.