Using theme.spacing() without any args returns a empty string. To get the default value it should be given 1 in the args.
theme.spacing() should give default spacing value.
theme.spacing() returns empty string.
| Tech | Version |
|--------------|---------|
| Material-UI | 4.0.0-beta.0 |
| React | 16.8.6 |
| Browser | Chromium: 74.0.3729.108 |
@vkasraj Interesting proposal. We could support it with a simple change:
--- a/packages/material-ui/src/styles/createSpacing.js
+++ b/packages/material-ui/src/styles/createSpacing.js
@@ -22,7 +22,7 @@ export default function createSpacing(spacingInput = 8) {
'It should be a number or a function.',
].join('\n'),
);
- transform = factor => {
+ transform = (factor = 1) => {
warning(
typeof factor === 'number',
`Expected spacing argument to be a number, got ${factor}`,
But what's the motivation for not doing theme.spacing(1)?
@oliviertassinari Currently I am doing theme.spacing(1) to get the default value. But, passing 1 every time seems redundant. Also If someone doesn't pass any args, It silently failed because empty string returned from the function. So, It is better to return the default value.
@vkasraj We need to change something, I agree. We have two options. We improve the warning, or we support a default factor of 1. I'm slightly leaning toward the default value path.
@vkasraj We need to change something, I agree. We have two options. We improve the warning, or we support a default factor of 1. I'm slightly leaning toward the default value path.
@oliviertassinari I also vote for the default value.
Most helpful comment
@oliviertassinari I also vote for the default value.