#Refactor complicated code
2 messages · Page 1 of 1 (latest)
Sure, I can help you simplify this code. However, please note that the refactoring process depends on the specific requirements of your project and the functionality you want to maintain. Here's a simplified version of your code:
{columns && columns.map((column, index) => {
const span = column.span;
const isFirst = index === 0;
const isLast = index === columns.length - 1;
const isPaddingRightOrNone = backgroundPadding === 'right' || backgroundPadding === 'none';
const columnClass = `column col-span-6 lg:col-span-${span} ${
isPaddingRightOrNone && isFirst ? 'lg:-ml-[var(--grid-margin-desktop)]' :
!isPaddingRightOrNone && isLast ? 'lg:-mr-[var(--grid-margin-desktop)]' : ''
}`;
return (
<section key={index} class={isFirst ? columnClass : `column hidden lg:block lg:col-span-${span}`}>
<Blocks blocks={column.blocks} global={global} />
</section>
);
})}
In this refactored code, I've removed the unnecessary columnHiddenClass variable and directly used its value in the ternary operator. I've also combined the conditions for setting the columnClass into a single line to make it more readable.