javascript - React toggle button issue -


i'm trying switch https://github.com/pgrimard/react-toggle-switch working in react project. working expected (it toggles , calls togglefeature function), i'm struggling understand how link each switch perform different action. grab sort of identifiable attribute in onclick event determine action carry out, i'm bit stuck on how in case.

heres current code (made bare-bones 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 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 1 have idea i'm doing wrong undefined on event, aswell perhaps idea's on how can provide own unique identifier each button read in onclick event?

heres examples of button: https://github.com/pgrimard/react-toggle-switch/blob/master/example/app/scripts/main.js#l12 if it's help

thanks!

while binding _togglefeature function, can give arguments called:

<switch classname= {this.props.description} onclick={this._togglefeature.bind(this, 'toggle1')} on={this.state.on1}/> <switch classname= {this.props.description} onclick={this._togglefeature.bind(this, 'toggle2')} on={this.state.on2}/> 

now can differentiate between toggles in handler:

_togglefeature(togglename) {   if (togglename === 'toggle1') {     // logic toggle 1   } else if (togglename === 'toggle2') {     // logic toggle 2   } } 

alternatively can have different handler functions each toggle, unless dynamically creating variable number of switches.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -