I just learned react, when button is clicked I want to navigate, but it doesn't and gives an error that 'push' is undefined, how to solve it?
import { Route, useHistory as history } from 'react-router-dom'
export default class TotalPrice extends Component {
checkout = (sum) => {
const order = {
total_bayar: sum,
menus: this.props.carts
}
axios.post(API_URL + "orders", order).then((res) => {
this.props.history.push('/order-success')
})
}
render() {
const sum = this.props.carts.reduce(function (result, item) {
return result + item.total_price;
}, 0);
return (
<Row className='fixed-bottom'>
<Col md={{span: 3, offset: 9}} className='py-4 px-4 total'>
<h4>
Total : <strong className='total-number'>Rp. {priceSplitter(sum)}</strong>
</h4>
<Button
variant="primary"
className="button-checkout"
onClick={() => this.checkout(sum)}
>
<FontAwesomeIcon icon={faShoppingCart} />
Checkout
</Button>
</Col>
</Row>
)
}
}