Destructuring Object in ES6
often use
const props = { label: 'label', text: 'text' } const { label, text } = props console.log(label) #=> 'label' console.log(text) #=> 'text'
default value
const props = { label: 'label' } const { label, text = 'text' } = props console.log(label) #=> 'label' console.log(text) #=> 'text'
alias
const props = { label: 'label', text: 'text' } const { label: l, text: t } = props console.log(l) #=> 'label' console.log(t) #=> 'text'
others
const props = { label: 'label', text: 'text', required: true, visible: true } const { label, text, options } = props console.log(label) #=> 'label' console.log(text) #=> 'text' console.log(options) #=> {required: true, visible: true}
Happy Hacking٩( ‘ω’ )و