Doc Site Getting Started WRONG
The Getting Started Installation and Usage sections indicated to:
import MuiPickersUtilsProvider from 'material-ui-pickers/MuiPickersUtilsProvider';
When it needs to be:
import { MuiPickersUtilsProvider } from 'material-ui-pickers';
Otherwise, you 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.
😱😱😱 That’s awful
I'm still getting this error even with import { MuiPickersUtilsProvider } from 'material-ui-pickers'. See https://codesandbox.io/s/qko2xqv93q.
@sebastianvoss For some reason the problem disappeared for me when I changed:
import { MuiPickersUtilsProvider } from 'material-ui-pickers';
to
import MuiPickersUtilsProvider from 'material-ui-pickers/MuiPickersUtilsProvider';
@danimbrogno-pml You should use only named exports or path imports, but not both together.
import { DatePicker, MuiPickersUtilsProvider } from 'material-ui-pickers';
or
import { DatePicker } from 'material-ui-pickers/DatePicker';
import MuiPickersUtilsProvider from 'material-ui-pickers/MuiPickersUtilsProvider';
I recommend named exports because bundles have more optimizations.
docs write
import { DatePicker } from 'material-ui-pickers';
it should be
import DatePicker from 'material-ui-pickers/DatePicker';
Can anybody tell what the problem is with the example from @sebastianvoss here: https://codesandbox.io/s/qko2xqv93q?
@stefensuhat Not necessary. import { DatePicker } from 'material-ui-pickers'; is recommended way.
@itoed Same problem as everywhere above. Import from only one place. https://codesandbox.io/s/q36ql75q3j
Ahh, I get it now from your exampe. Thank you @TrySound!
@TrySound yeah, you are right but what you say does not work for DateFnsUtils or, in my case, MomentUtils. Which is rather unintuitive and sent me on a debugging adventure.
Anyway: Thanks for this great tool.
Also: The docs are not consistent on importing utils:
- according to the readme it is
import MomentUtils from 'material-ui-pickers/moment-utils'. Which errors in my case - according to the documentation website it is
import MomentUtils from 'material-ui-pickers/utils/moment-utils'
Bad merge. Never mind. These utils will be provided as separate packages soon https://github.com/dmtrKovalenko/date-io
Should we have to install date-io instead of individual utils , how to resolve the issue 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.
@kamarajuPrathi not yet. Now you must check the path imports consistency through your app
@dmtrKovalenko how should fix the above issue <MuiPickersUtilsProvider utils={DateFnsUtils}><InlineDatePicker
key={index}
label={ label }
value={ value }
clearable
onChange={ (e) => onChange(e) }
/></MuiPickersUtilsProvider> do you see anything wrong in this , i get this error 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.
Yes, use named imports from material-ui-pickers entry point. If you still get the error show your imports.
@TrySound @dmtrKovalenko
import { InlineDatePicker } from 'material-ui-pickers'
import DateFnsUtils from "material-ui-pickers/utils/date-fns-utils";
import MuiPickersUtilsProvider from "material-ui-pickers/MuiPickersUtilsProvider";
these are the imports
Import provider from entry point too. I already attached the example above.
import { InlineDatePicker } from 'material-ui-pickers';
this import giving me error.