You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -333,45 +333,36 @@ Refer to [this example](https://github.com/mui-org/material-ui/blob/next/example
333
333
334
334
## Class names
335
335
336
-
You may have noticed that the class names generated by `@material-ui/styles` are **non-deterministic**,
337
-
so you can't rely on them to stay the same.
338
336
The class names are generated by [the class name generator](/css-in-js/api/#creategenerateclassname-options-class-name-generator).
339
337
340
-
Let's take the following style as an example:
338
+
### Without a name
341
339
342
-
```jsx
340
+
By default, the class names generated by `@material-ui/styles` are **non-deterministic**, you can't rely on them to stay the same. Let's take the following style as an example:
341
+
342
+
```js
343
343
constuseStyles=makeStyles({
344
344
root: {
345
345
opacity:1,
346
346
},
347
-
}, {
348
-
name:'AppBar',
349
347
});
350
348
```
351
349
352
-
This will generate a class name such as `AppBar-root-123`. However, the following CSS won't work:
353
-
354
-
```css
355
-
.AppBar-root-123 {
356
-
opacity: 0.6;
357
-
}
358
-
```
350
+
This will generate a class name such as `makeStyles-root-123`.
359
351
360
-
You have to use the `classes` property of a component to override them.
361
-
The non-deterministic nature of the class names enables optimization for development and production –
362
-
they are easy to debug in development, and as short as possible in production:
352
+
You have to use the `classes` property of a component to override the class names.
353
+
The non-deterministic nature of the class names enables style isolation.
363
354
364
-
- In **development**, the class name will be: `.AppBar-root-123`, following this logic:
355
+
- In **development**, the class name is: `.makeStyles-root-123`, following this logic:
We provide an option to make the class names **deterministic** with the [`dangerouslyUseGlobalCSS`](/css-in-js/api/#creategenerateclassname-options-class-name-generator) option. When turned on, the class names will look like this:
403
-
404
-
- development: `.AppBar-root`
405
-
- production: `.AppBar-root`
406
-
407
-
⚠️ **Be cautious when using `dangerouslyUseGlobalCSS`.**
408
-
Relying on it for code running in production has the following implications:
409
-
410
-
- It's harder to keep track of `classes` API changes between major releases.
411
-
- Global CSS is inherently fragile.
412
-
413
-
⚠️ When using `dangerouslyUseGlobalCSS` standalone (without Material-UI), you should name your style sheets using the `options` parameter:
Copy file name to clipboardExpand all lines: docs/src/pages/css-in-js/api/api.md
+10-11Lines changed: 10 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,9 @@ A function which returns [a class name generator function](http://cssinjs.org/js
9
9
#### Arguments
10
10
11
11
1.`options` (*Object*[optional]):
12
-
-`options.dangerouslyUseGlobalCSS` (*Boolean*[optional]): Defaults to `false`. Makes the Material-UI class names deterministic.
13
-
-`options.productionPrefix` (*String*[optional]): Defaults to `'jss'`. The string used to prefix the class names in production.
14
-
-`options.seed` (*String*[optional]): Defaults to `''`. The string used to uniquely identify the generator. It can be used to avoid class name collisions when using multiple generators.
12
+
-`options.disableGlobal` (*Boolan*[optional]): Default to `false`. Disable the generation of deterministic class names.
13
+
-`options.productionPrefix` (*String*[optional]): Defaults to `'jss'`. The string used to prefix the class names in production. You can disable the minification in production by providing an empty string.
14
+
-`options.seed` (*String*[optional]): Defaults to `''`. The string used to uniquely identify the generator. It can be used to avoid class name collisions when using multiple generators in the same document.
@@ -212,11 +211,11 @@ It should preferably be used at **the root of your component tree**.
212
211
213
212
| Name | Type | Default | Description |
214
213
|:-----|:-----|:--------|:------------|
215
-
|<spanclass="prop-name required">children *</span>|<spanclass="prop-type">node</span>|| Your component tree. |
216
-
|<spanclass="prop-name">disableGeneration</span>|<spanclass="prop-type">bool</span>| false | You can disable the generation of the styles with this option. It can be useful when traversing the React tree outside of the HTML rendering step on the server. Let's say you are using react-apollo to extract all the queries made by the interface server-side. You can significantly speed up the traversal with this property. |
217
-
|<spanclass="prop-name">generateClassName</span>|<spanclass="prop-type">func</span>|| JSS's class name generator. |
218
-
|<spanclass="prop-name">injectFirst</span>|<spanclass="prop-type">bool</span>| false | By default, the styles are injected last in the <head> element of your page. They gain more specificity than any other style sheet on your page e.g. CSS modules, styled components. If you want to override the Material-UI's styles, set this prop. |
| disableGeneration | bool | false | You can disable the generation of the styles with this option. It can be useful when traversing the React tree outside of the HTML rendering step on the server. Let's say you are using react-apollo to extract all the queries made by the interface server-side. You can significantly speed up the traversal with this property. |
216
+
| generateClassName | func || JSS's class name generator. |
217
+
| injectFirst | bool | false | By default, the styles are injected last in the <head> element of your page. They gain more specificity than any other style sheet on your page e.g. CSS modules, styled components. If you want to override the Material-UI's styles, set this prop. |
218
+
| jss | object || JSS's instance. |
220
219
221
220
#### Examples
222
221
@@ -243,8 +242,8 @@ It should preferably be used at **the root of your component tree**.
243
242
244
243
| Name | Type | Default | Description |
245
244
|:-----|:-----|:--------|:------------|
246
-
|<spanclass="prop-name required">children *</span>|<spanclass="prop-type">node</span>|| Your component tree. |
247
-
|<spanclass="prop-name required">theme *</span>|<spanclass="prop-type">union: object | func</span>|| A theme object. You can provide a function to extend the outer theme. |
245
+
| children *| node || Your component tree. |
246
+
| theme *| union: object | func || A theme object. You can provide a function to extend the outer theme. |
0 commit comments