Material-ui: styled("div")(t=> ({})) @4.0.0-alpha.4

Created on 21 Mar 2019  路  3Comments  路  Source: mui-org/material-ui

import CssBaseline from "@material-ui/core/CssBaseline";
import { createMuiTheme, Theme } from "@material-ui/core/styles";
import { styled, ThemeProvider } from "@material-ui/styles";
import * as React from "react";
const theme = createMuiTheme({});
const Box = styled("div")((t: Theme) => ({
    backgroundColor: t.palette.primary.main,
    height: 100,
    width: 100,
}));
export default function Bootstrap() {
    return (
        <ThemeProvider theme={theme}>
            <CssBaseline />
            <Box />
        </ThemeProvider>
    );
}

灞忓箷蹇収 2019-03-21 涓嬪崍8 17 22

docs good first issue

Most helpful comment

https://github.com/mui-org/material-ui/blob/997324d52467e3a7b7a8058c0ba8309d04d4ddf6/packages/material-ui-styles/src/styled/styled.js#L106

Following this line, you need use destructuring declaration of variable form, or get property of t.theme,

so, your code may be this:

import CssBaseline from "@material-ui/core/CssBaseline";
import { createMuiTheme, Theme } from "@material-ui/core/styles";
import { styled, ThemeProvider } from "@material-ui/styles";
import * as React from "react";
const theme = createMuiTheme({});
const Box = styled("div")(({ theme }) => ({
    backgroundColor: theme.palette.primary.main,
    height: 100,
    width: 100,
}));
export default function Bootstrap() {
    return (
        <ThemeProvider theme={theme}>
            <CssBaseline />
            <Box />
        </ThemeProvider>
    );
}

Please, let me know if it works

All 3 comments

https://github.com/mui-org/material-ui/blob/997324d52467e3a7b7a8058c0ba8309d04d4ddf6/packages/material-ui-styles/src/styled/styled.js#L106

Following this line, you need use destructuring declaration of variable form, or get property of t.theme,

so, your code may be this:

import CssBaseline from "@material-ui/core/CssBaseline";
import { createMuiTheme, Theme } from "@material-ui/core/styles";
import { styled, ThemeProvider } from "@material-ui/styles";
import * as React from "react";
const theme = createMuiTheme({});
const Box = styled("div")(({ theme }) => ({
    backgroundColor: theme.palette.primary.main,
    height: 100,
    width: 100,
}));
export default function Bootstrap() {
    return (
        <ThemeProvider theme={theme}>
            <CssBaseline />
            <Box />
        </ThemeProvider>
    );
}

Please, let me know if it works

Correct, we should document it.

Typings is also wrong. I will make a PR for it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathanmarks picture nathanmarks  路  100Comments

cfilipov picture cfilipov  路  55Comments

aranw picture aranw  路  95Comments

tdkn picture tdkn  路  57Comments

garygrubb picture garygrubb  路  57Comments