First of all, my excuses if I'm not expressing myself correctly, I'm still a bit confused with Typescript.
I have a styled button from Material-UI and I'm not sure how to proceed with making this button reusable throughout the whole app. I basically would like the button to receive a prop such as {buttonText} or so, so I can just use it in multiple pages but with different labels.
import { makeStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
const useStyles = makeStyles({
backButton: {
background: 'linear-gradient(45deg, #9AA5B0 30%, #9AA5B0 90%)',
border: 0,
borderRadius: 25,
boxShadow: '0 2px 4px rgba(0, 0, 0, .5)',
color: 'white',
fontFamily: 'Poppins, sans-serif',
fontSize: 15,
height: 37,
padding: '0 20px',
textTransform: 'none',
},
});
export default function BackButton(): React.ReactElement {
const classes = useStyles();
return (
<Button className={classes.backButton} startIcon={<ChevronLeftIcon />}>
{buttonText}
</Button>
);
}
So when I insert the button component in another page, I could just give a value to the props and then the right label would show on my button.
<div>
<PrimaryButton />
<BackButton label={buttonText}/>
</div>
Any suggestions on how to make this work, using types?
Many thanks in advance!