Gutenberg React state example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { __ } = wp.i18n; | |
const { Component } = wp.element; | |
const el = wp.element.createElement; | |
export default class Select extends Component { | |
constructor( props ) { | |
super( ...props ); | |
this.selectCallback = this.selectCallback.bind(this); | |
this.state = { | |
current_editing: 'The bold attribute has NOT been changed', | |
change_time: 0 | |
} | |
} | |
selectCallback(event){ | |
this.setState({change_time: this.state.change_time+=1 }); | |
this.setState({current_editing: 'The bold attribute HAS been changed ' + this.state.change_time + ' times'}); | |
this.props.changeHandler(event); | |
} | |
render() { | |
return el( | |
'div', | |
{}, | |
[ | |
el( | |
'div', | |
{}, | |
this.state.current_editing, | |
), | |
el( | |
'select', | |
{ | |
onChange: this.selectCallback, | |
id: this.props.id, | |
value: this.props.value | |
}, | |
[ | |
el( | |
'option', | |
{ | |
value: 'true' | |
}, | |
__( 'Bold On', 'text-domain' ) | |
), | |
el( | |
'option', | |
{ | |
value: 'false' | |
}, | |
__( 'Bold Off', 'text-domain' ) | |
) | |
] | |
) | |
] | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment