material-ui-pickers icon indicating copy to clipboard operation
material-ui-pickers copied to clipboard

Doc Site Getting Started WRONG

Open kyledgreen opened this issue 8 years ago • 28 comments

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.

kyledgreen avatar Oct 25 '18 22:10 kyledgreen

😱😱😱 That’s awful

dmtrKovalenko avatar Oct 26 '18 04:10 dmtrKovalenko

I'm still getting this error even with import { MuiPickersUtilsProvider } from 'material-ui-pickers'. See https://codesandbox.io/s/qko2xqv93q.

sebastianvoss avatar Oct 26 '18 10:10 sebastianvoss

@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 avatar Oct 26 '18 12:10 danimbrogno-pml

@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';

TrySound avatar Oct 26 '18 13:10 TrySound

I recommend named exports because bundles have more optimizations.

TrySound avatar Oct 26 '18 13:10 TrySound

docs write

import { DatePicker } from 'material-ui-pickers';

it should be

import DatePicker from 'material-ui-pickers/DatePicker';

stefensuhat avatar Oct 28 '18 05:10 stefensuhat

Can anybody tell what the problem is with the example from @sebastianvoss here: https://codesandbox.io/s/qko2xqv93q?

itoed avatar Oct 29 '18 18:10 itoed

@stefensuhat Not necessary. import { DatePicker } from 'material-ui-pickers'; is recommended way.

TrySound avatar Oct 29 '18 18:10 TrySound

@itoed Same problem as everywhere above. Import from only one place. https://codesandbox.io/s/q36ql75q3j

TrySound avatar Oct 29 '18 18:10 TrySound

Ahh, I get it now from your exampe. Thank you @TrySound!

itoed avatar Oct 29 '18 19:10 itoed

@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.

barbalex avatar Oct 30 '18 12:10 barbalex

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'

barbalex avatar Oct 30 '18 12:10 barbalex

Bad merge. Never mind. These utils will be provided as separate packages soon https://github.com/dmtrKovalenko/date-io

TrySound avatar Oct 30 '18 13:10 TrySound

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 avatar Nov 01 '18 16:11 kamarajuPrathi

@kamarajuPrathi not yet. Now you must check the path imports consistency through your app

dmtrKovalenko avatar Nov 01 '18 16:11 dmtrKovalenko

@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.

kamarajuPrathi avatar Nov 01 '18 16:11 kamarajuPrathi

Yes, use named imports from material-ui-pickers entry point. If you still get the error show your imports.

TrySound avatar Nov 01 '18 16:11 TrySound

@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

kamarajuPrathi avatar Nov 01 '18 18:11 kamarajuPrathi

Import provider from entry point too. I already attached the example above.

TrySound avatar Nov 01 '18 19:11 TrySound

import { InlineDatePicker } from 'material-ui-pickers';

this import giving me error.

deeptikanta avatar Nov 06 '18 11:11 deeptikanta