简体   繁体   中英

Negate A Destructured Value Assigned To A New Variable

I have the following code in a React component.

const { isDisclosed: showDisclosureButton } = this.state

The problem is that I need the value of showDisclosureButton to be a negation of this.state.isDisclosed . The equivalent of:

const showDisclosureButton = !this.state.isDisclosed

Is there any way to negate a destructured value that is being assigned to a new variable?

No, there is not. Just write

const showDisclosureButton = !this.state.isDisclosed

It is simple, clear, and shorter than any destructuring could be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM