Last active
November 16, 2021 10:14
-
-
Save herr-vogel/0b5d4f3c28f08dc6cc4a2fd4f7b4a4df to your computer and use it in GitHub Desktop.
Using Material-UI Button with Next.js Link
I had a ref
error for my wrapped Material UI Button in a NextJS Link, which is what I was searching for when I found this thread. I didn't need any of the above, except wrapping my button with React.forwardRef
import { makeStyles } from "@material-ui/core/styles";
import { Button as MuiButton, ButtonProps } from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
root: {
// your styles
},
}));
interface Props extends ButtonProps {}
export const Button: React.FC<Props> = React.forwardRef((props, ref) => {
const classes = useStyles();
return <MuiButton ref={ref} className={classes.root} {...props} />;
});
Button.displayName = "Button";
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One more wrapper for both Link and Button components can be found here (typescript version) https://gist.github.com/kachar/028b6994eb6b160e2475c1bb03e33e6a