Refactor LinkButton into class component
because setting defaultProps on function components is deprecated
This commit is contained in:
parent
19eb3f531d
commit
a6b13ce56f
|
|
@ -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';
|
||||||
|
|
||||||
export function LinkButton(props) {
|
class LinkButtonComponent extends React.Component {
|
||||||
const router = useRouter();
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.defaultProps = {
|
||||||
|
outline: true,
|
||||||
|
color: 'secondary'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const handleClick = e => {
|
handleClick(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
router.push(props.href);
|
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'
|
||||||
};
|
};
|
||||||
|
|
||||||
return (<Button outline='true' onClick={handleClick}>{props.children}</Button>);
|
// export default withRouter(LinkButton);
|
||||||
|
|
||||||
|
export function LinkButton(props) {
|
||||||
|
const router = useRouter();
|
||||||
|
return (<LinkButtonComponent {...props} router={router} />);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue