LoginSignup
5
4

More than 5 years have passed since last update.

styled-components + TypeScript + Material-UI

Last updated at Posted at 2018-07-21

strict モードではエラーになる。

const InlineInput = styled(TextField)`
  && {
    margin-top: 36px;
  }
`

React.SFC に、型をキャストしてあげれば良い

const InlineInput = styled(TextField as React.SFC)`
  && {
    margin-top: 36px;
  }
`

ref: https://github.com/mui-org/material-ui/issues/9756

追記

この書き方だと、Prop を渡したい時に困る・・・

interface Props {
  value: string
  onChange: () => void
  label?: string
}

const InlineInput = styled(TextField as React.SFC<Props>)`
  && {
    margin-top: 36px;
  }

などとしなければいけなくなる・・・

Material UI のPropsを取ってくれば良いかもしれない。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4