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.

[DatePicker] Remove the dateAdapter prop

See original GitHub issue

The dateAdapter prop is exposed as a sugar helper in order to allow this diff:

-<LocalizationProvider dateAdapter={x}>
-  <DatePicker />
-</LocalizationProvider>+
+<DatePicker dateAdapter={x} />

As far as I can envision the requirement of developers, I can only see a marginal use case for the prop:

  • 70% of the cases, you are a developer, you want to get things down, you don’t have time to work on the tree-shaking of your application, you have a sprint to make progress on. You use LocalizationProvider at the root of your app.
  • 30% of the cases, you have found time to dedicate on tree-shaking. You figure that you can solve the problem by creating a wrapper component for each date picker component. You create the wrapper, move the LocalizationProvider inside it, for instance:
import { DatePicker, DatePickerProps, LocalizationProvider } from '@material-ui/lab';
import dateAdapter from 'path-to-date-adapter';

const DatePicker = React.forwardRef(function DatePicker(props: DatePickerProps, ref: React.Ref<unknown>)) {
  return (
    <LocalizationProvider dateAdapter={dateAdapter}>
      <DatePicker ref={ref} {...props} />
    </LocalizationProvider>
  );
}

export default DatePicker;

Another advantage of dropping dateAdapter avoids having people ask what option they should use between the provider and the prop and also to prune the codebase of code that isn’t used frequently enough to justify the added complexity.

  • I wonder if we should expose withDateAdapter as a public higher-order component? Probably not
  • I wonder about making a poll to figure out what developers use. Happy to skip this part

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
eps1loncommented, Nov 22, 2020

I think that having x different ways to do things is to be encouraged if the x approaches come with different enough set of pros & cons and developers are interested in the different options.

Ok. I was not talking about this. I was talking about doing one thing. Not doing two things.

1reaction
eps1loncommented, Nov 22, 2020

Same argument as always: Provide one API to do one thing not two. Glad you’re following here but I would hope you apply it everywhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[DatePicker] Remove the dateAdapter prop #23670 - GitHub
The dateAdapter prop is exposed as a sugar helper in order to allow this diff: - - - + + ... [DatePicker] Remove...
Read more >
How can I clear MUI DatePicker input? - Stack Overflow
Store a date field in state, passed as the value prop to DatePicker · Change the date to null when desired to 'clear'...
Read more >
Datepicker - Angular Material
Disabling parts of the datepicker. As with any standard <input> , it is possible to disable the datepicker input by adding the disabled...
Read more >
Datepicker in Angular using mat-datepicker | Material Design
We can disable the datepicker by adding disabled property to the input element. <mat-form-field> <input matInput [matDatepicker]="disabledatepicker" ...
Read more >
React Date Picker component - MUI X
It's possible to render any date picker without the modal/popover and text field. This can be helpful when building custom popover/modal containers.
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