Material-ui-pickers: Any DatePicker component immediately errors with missing utils from Context

Created on 11 Dec 2018  路  2Comments  路  Source: mui-org/material-ui-pickers

Environment

| Tech | Version |
|---------------------|---------|
| material-ui-pickers |2.0.4 |
| material-ui |@material-ui/[email protected] |
| React |16.6.3 |
| Browser |Chrome v70.0.3538.110|
| Peer library |[email protected], @date-io/[email protected]|

Steps to reproduce

  1. Add <MuiPickersUtilsProvider utils={DateFnsUtils} /> to top-level component
  2. Add <InlineDatePicker onChange={console.log} value={new Date()} /> somewhere in app
  3. Get error:
Can not find utils in context.
You either a) forgot to wrap your component tree in MuiPickersUtilsProvider;
or b) mixed named and direct file imports.
Recommendation: use named imports from the module index.

Expected behavior

It rendered a basic inline datepicker.

Actual behavior

I get an error, see above.

Live example

I've created a basic CodeSandbox that (should) use the most up-to-date versions of all the libraries.
Basic CodeSandbox

Additional Information

I can't get anything to work with this basic setup, it is not just the InlineDatePicker that is faulty. I also tried using the basic DatePicker component, (because I wanted to copy the "Integration with Formik" guide), but its propTypes stated that it needed an utils prop that I couldn't find mentioned anywhere in the docs. Let me know if you need more information from me.

Thanks!

Most helpful comment

Do not mix direct and named imports

https://codesandbox.io/s/r405k1w8yn

All 2 comments

Do not mix direct and named imports

https://codesandbox.io/s/r405k1w8yn

oh THAT was what it meant, thanks! I confused it with "named" and "default" imports, and made absolutely sure that I wasn't using any default imports.

Sorry for the inconvenience, thanks for the help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

basselAhmed picture basselAhmed  路  3Comments

sakulstra picture sakulstra  路  3Comments

brett-patterson picture brett-patterson  路  3Comments

idrm picture idrm  路  3Comments

danmce picture danmce  路  3Comments