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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners