Maybe I’m tired, but I’m not seeing any reason why this onSelectionChange is not working!???
This is my first file (a list of cards):
import React from 'react';
import { Button, Row, Col, Card } from 'antd';
import { VendorCard } from '../common'
export class VendorList extends React.Component {
constructor(props){
super(props);
this.onSelectionChange = this.onSelectionChange.bind(this);
this.state = {
compareVendorIds: [],
}
}
onSelectionChange(value, vendorId){
console.log(value);
console.log(vendorId);
if (value) {
let currentState = this.state.compareVendorIds;
currentState.push(vendorId)
this.setState({compareVendorIds: currentState});
}
}
render( ){
const {vendors} = this.props;
return (
<Row>
{vendors.map((vendor)=>{
return (
<Col key={vendor._id} span='8'>
<VendorCard
item={vendor} compareSelection={this.onSelectionChange}
/>
</Col>
);
})}
</Row>
);
}
}
And this is the card that is receiving this.onSelectionChange
import React from 'react';
import { Button, Row, Col, Card, message, Checkbox } from 'antd';
const FeatureCard_Top = ({item, compareSelection}) => {
return (
<Row style={{height: 250}}>
<Checkbox onChange={ (value)=> compareSelection(value.target.checked, item._id) } />
<h1>{item.title}</h1>
</Row>
);
}
class VendorCard extends React.Component {
constructor(props){
super(props);
}
render(){
const { item, compareSelection } = this.props;
return (
<Card>
<FeatureCard_Top
item={item}
compareSelection={(value, vendorId)=>compareSelection(value, vendorId)}
/>
</Card>
);
}
}
export { VendorCard };