How to bind this plus an additional option to the click callback to React?

Hello, there is a component
ProductSingle.js

import React {Component} from 'react';
import {Link} from 'react-router-dom';
ProductPrices import from './ProductPrices';
import ReactHtmlParser from 'react-html-parser';
import history from '../../helpers/history';

ProductSingle class extends Component {

constructor(props){
super(props);

 this.postSelectedHandler = this.postSelectedHandler.bind(this, id);
}

 postSelectedHandler(id, e){
e.preventDefault();

 console.log( 'id', id );
 console.log( 'e', e );
}

render(){

 const {image, title, excerpt, descrtitle, descrtext, regular_price, sale_price, discount, currency, id, matchPath} = this.props;

 return (
 <div className="good__item">
 <div className="good__itemInner">
 <div className="good__itemContent">
 <div className="good__itemHeader">
 <img className="good__itemImage" src={image} data-id={id} alt=""/>
</div>

 <div className="good__itemTitle">{ReactHtmlParser(title)}</div>

 <div className="good__itemExcerpt">{ReactHtmlParser(excerpt)}</div>

 <div className="good__itemDescr">
<a
href={`${matchPath}/${id}`}
className="good__itemDescrTitle"
onClick={this.postSelectedHandler}
>
{ReactHtmlParser(descrtitle)}
</a>
</div>

 <ProductPrices regular_price={regular_price} sale_price={sale_price} currency={currency} />
</div>
</div>
</div>
);
}
}

export default ProductSingle;

It has a link
<a
href={`${matchPath}/${id}`}
className="good__itemDescrTitle"
onClick={this.postSelectedHandler}
>

Handler
postSelectedHandler(id, e){
e.preventDefault();

 console.log( 'id', id );
 console.log( 'e', e );
 }

Bind this in the designer, guided by the guideline

why is id undefined? How to bind through the designer an additional parameter?

Thank you.
March 19th 20 at 09:05
1 answer
March 19th 20 at 09:07
Solution
why is id undefined?

And you get undefined and pass.

Corrected version:
constructor(props){
super(props);

 this.postSelectedHandler = this.postSelectedHandler.bind(this, this.props.id);
}
Thank you - niko commented on March 19th 20 at 09:10

Find more questions by tags React