1

What would be the alternative to && !(Object.keys(dataSource.attributes).length === 0)); the following validation, any ways of this to be a map of validation / title / render

isProductAttributesTabEmpty() {
  const dataSource = this.getDataSource();

  return !(dataSource
    && dataSource.attributes
    && !(Object.keys(dataSource.attributes).length === 0));
}
Shared User
  • 105
  • 9

1 Answers1

2

One option you might prefer would be to use optional chaining in combination with alternating with an empty object to pass into Object.keys:

isProductAttributesTabEmpty() {
  const dataSource = this.getDataSource();
  return Object.keys(dataSource?.attributes || {}).length === 0;
}
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320