const question = this.props.question
const answer = question.answer
Refactor the above snippet to use destructuring.
const { question } = this.props
const { answer } = question
How can I refactor this destructuring to one line?
If I do this one, const { question : { answer } } = this.props
, I won't get the reference for question
?
You can reference the same property multiple times when destructuring:
const { question, question: { answer } } = this.props;
const props = {
question: {
answer: 'answer'
}
};
const { question, question: { answer } } = props;
console.log(question);
console.log(answer);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With