Send Data as props to other component using history.push

Viewed 90

So I have my BikeCardContainer in which when I click on button it should navigate to other page and send current object data

handleClick() {
console.log(this.props.bikes);
this.props.propdata.history.push({
  pathname: '/Checkout',
  state: this.props.bikes
});

}

and I want to know how to access this data in receiving page.

    class Checkout extends Component {
  constructor(props) {
    super(props);
    console.log(this.props.bikes)
    this.state = {};
    this.confirmClick = this.confirmClick.bind(this);
    this.goBackClick = this.goBackClick.bind(this);
  }
1 Answers

Pass like this

handleClick() {
console.log(this.props.bikes);
this.props.history.push({
  pathname: '/Checkout',
  state: this.props.bikes
});

Access like this

const location = useLocation();
console.log(location);

in Class component

this.props.location
Related