I am trying to implement a HOC for MaterialUI Button component:
import {Button as MUIButton, ButtonProps} from '@material-ui/core';
import * as React from 'react';
export const Button = (props: ButtonProps) => <MUIButton {...props} />;
and i use it like this:
import {Button} from '../hocs/button.tsx';
import {Link} from 'react-router-dom';
...
<Button
variant='contained'
color='primary'
component={Link}
to={`${url}/new`}
>
Add something
</Button>
But i meet an error
Property 'component' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; classes?: { root?: string | undefined; label?: string | undefined; text?: string | undefined; textPrimary?: string | undefined; ... 24 more ...; iconSizeLarge?: string | undefined; } | undefined; ... 9 more ...; variant?: "text" | ... 2 more ... | undefined; } & Pick<......'. TS2322
So, what i am doing wrong and how i can fix it?
Thanks ahead.
Edit: I guess, the problem is ButtonProps is a generic, dependant on props.component
type.
children
fromprops
, if you just spreadprops
, it's all gonna work. Children are a prop just like any other. – John Smith