reactjs - Change button text dynamically in material-ui -


if try change label button got error because label read property. how change button text dinamically?

export default class tagger extends component {   static proptypes = {     name: proptypes.string   }    constructor(props) {     super(props)     this.state = {       disabled: true     }     this.enableedit = this.enableedit.bind(this)   }    componentdidmount() {     this.editbutton = react.finddomnode(this.refs.editbutton)   }   enableedit() {     this.setstate({disabled: !this.state.disabled})     this.refs.editbutton.props.label = 'save'   }    render() {     return (       <div>         <raisedbutton onclick={this.enableedit} label='modify' primary={true} ref='editbutton' />       </div>     )   } } 

props read-only , can't mutate/edit them

you can change props instead of mutating them. set value of prop state , pass it.

export default class tagger extends component {   static proptypes = {     name: proptypes.string,   }    constructor(props) {     super(props)     this.state = {       disabled: true,       lable = "modilfy" // inital state     }     this.enableedit = this.enableedit.bind(this)   }    componentdidmount() {     this.editbutton = react.finddomnode(this.refs.editbutton)   }   enableedit() {     this.setstate({     disabled: !this.state.disabled,     label:"save" // update here     })   }    render() {     // take value state , pass it, no need of ref     return (       <div>         <raisedbutton onclick={this.enableedit} label={this.state.label} primary={true} />       </div>     )   } } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -