Heads up: I'm going to use Vue/Alpine lingo in this article, but I think this pattern applies to lots of different tools. If you clicked a different row, the previous one would become "deactivated" and the new one would "activate".

Now, we can add a click listener to set the new active row when a different one is clicked: let activeRow = 12 document.querySelectorAll('tr').forEach((row) => { row.addEventListener('click', () => { activeRow = row.id }) if (row.id === activeRow) { row.classList.add('active')} else { row.classList.remove('active')} })

Now, because when a single row is clicked, only a single reactive boolean is switched, and only a single effect updates (instead of ten thousand). Before, because "activeRow" only ever contained a single value, there was only ever a single row active at a time.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners