Terminal state in ES6 destruction object
I wrote a stateless function, in this function I am using a Destructuring object declaration, but one of my variables has a condition. I wrote this with a triple condition. but I cannot declare it in the Destructuring assignment structure.
This is my declaration:
const pageNo = props.filters.pageno
? props.filters.pageno -1
: 0;
const {
data: {
result: {
total : total
} = {}
},
tags: {
result: {
categoryFilter: {
Title : title
} = {}
} = {}
}
} = props;
+3
AmerllicA
source
to share
2 answers
You cannot directly. You can do:
const {filters: {pageno}} = props;
const realPageno = pageno ? pageno - 1 : 0;
+3
TPReal
source
to share
const {
data: {
result: {
total : total = 0
} = {}
}={},
filters: {
pageno: TempPageNo = 0
}={},
tags: {
result: {
categoryFilter: {
Title : title = "something"
} = {}
} = {}
}={}
} = props;
const pageno = TempPageNo ? TempPageNo - 1 : TempPageNo
+2
AmerllicA
source
to share