Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ternary condition in ES6 destructuring object

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;
like image 901
AmerllicA Avatar asked Oct 16 '25 16:10

AmerllicA


1 Answers

You cannot directly. You can do:

const {filters: {pageno}} = props;
const realPageno = pageno ? pageno - 1 : 0;
like image 57
TPReal Avatar answered Oct 19 '25 12:10

TPReal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!