I wrote a stateless function, in this function I use a destructuring object declaration, but one of my variables has conditions. I wrote it with a ternary condition. but I cannot declare it in the destructuring assignment structure.
This is my declaration:
const {
data: { result: { total: total } = {} },
tags: { result: { categoryFilter: { Title: title } = {} } = {} }
} = props;
const pageNo = props.filters.pageno
? props.filters.pageno - 1
: 0;
You cannot directly. You can do:
const {filters: {pageno}} = props;
const realPageno = pageno ? pageno - 1 : 0;
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