Quick way to avoid no-param-reassign error

Quite a common eslint error that comes up is for the no-param-reassign rule. It happens to me quite often in circumstances like this:

const buttons = document.querySelectorAll('button');
buttons.forEach(button => {
    button.style.display = 'none'; // This line will trigger the eslint error
});

A nice little way of subverting this:

const buttons = document.querySelectorAll('button');
buttons.forEach(button => {
    Object.assign(button.style, {
        display: 'none',
    });
});

I feel like there must be a better way to do this, a more functional programming style solution, perhaps using an object spread {...}. Let me know!

Quick way to avoid no-param-reassign error
Share this