Using typescript and want to set styling for Material UI component with styled-components.
But type error happens with StyledComponent showing Type '{ children: string; }' is missing the following properties
import React, { PureComponent } from 'react';
import styled from 'styled-components'; // ^4.1.3
import { Button } from '@material-ui/core'; // ^3.9.1
class TestForm extends PureComponent {
render() {
return (
<>
<Button style={{ backgroundColor: 'red' }}>Work</Button>{/* OK */}
<StyledButton>Doesn't work</StyledButton>{/* Type Error happens here <=============== */}
{/**
Type '{ children: string; }' is missing the following properties from type 'Pick<Pick<(ButtonProps & RefAttributes<Component<ButtonProps, any, any>>) | (ButtonProps & { children?: ReactNode; }), "form" | "style" | "title" | "disabled" | "mini" | ... 279 more ... | "variant"> & Partial<...>, "form" | ... 283 more ... | "variant">': style, classes, className, innerRef [2739]
*/}
</>
);
}
}
const StyledButton = styled(Button)`
background: blue;
`;
export default TestForm;
It is showing children prop is missing.
I have tried the following too but still doesn't work.
const StyledButton = styled(Button)<{ children: string; }>`
background: blue;
`;
Does anyone know how to use Material UI with styled-components in typescript?