I'm trying to get this switch https://github.com/pgrimard/react-toggle-switch working in my react project. It is currently working as expected (it toggles and calls the toggleFeature function), however i'm struggling to understand how I would actually link each switch to perform a different action. Normally I would just grab some sort of identifiable attribute in the onClick event to determine which action to carry out, But i'm a bit stuck on how to do it in this case.
Heres my current code (Made it as bare-bones as possible)
class FeatureItem extends React.Component {
constructor(props) {
super(props);
this.state = {on: props.flag};
}
_toggleFeature(e) {
console.log(e); // Undefined
console.log("ASSD"); // Called on the toggle
}
render () {
<div className="example-usage">
<p>Switch state: {this.state.on ? 'On' : 'Off'}</p>
<Switch className= {this.props.description} onClick={this._toggleFeature.bind(this)} on={this.state.on}/>
</div>
)
}
};
Does any one have any idea what i'm doing wrong to get undefined on the event, Aswell as perhaps some idea's on how I can provide my own unique identifier to each button which I could read in the onClick event?
Heres examples of the button: https://github.com/pgrimard/react-toggle-switch/blob/master/example/app/scripts/main.js#L12 if it's any help
Thanks!