Refactor LinkButton into class component

because setting defaultProps on function components is deprecated
This commit is contained in:
Thor77 2022-06-11 22:51:57 +02:00
parent 19eb3f531d
commit a6b13ce56f
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
1 changed files with 31 additions and 7 deletions

View File

@ -2,13 +2,37 @@ import {Button} from 'reactstrap';
import {useRouter} from 'next/router'; import {useRouter} from 'next/router';
import React from 'react'; import React from 'react';
class LinkButtonComponent extends React.Component {
constructor(props) {
super(props);
this.defaultProps = {
outline: true,
color: 'secondary'
};
}
handleClick(e) {
e.preventDefault();
this.props.router.push(this.props.href);
}
render() {
return (
<Button outline={this.props.outline} color={this.props.color} onClick={e => this.handleClick(e)}>
{this.props.children}
</Button>
);
}
}
LinkButtonComponent.defaultProps = {
outline: true,
color: 'secondary'
};
// export default withRouter(LinkButton);
export function LinkButton(props) { export function LinkButton(props) {
const router = useRouter(); const router = useRouter();
return (<LinkButtonComponent {...props} router={router} />);
const handleClick = e => {
e.preventDefault();
router.push(props.href);
};
return (<Button outline='true' onClick={handleClick}>{props.children}</Button>);
} }