Search code examples
javascriptreactjscoding-styleeslint

Eslint no-return-assing and no-param-reassign error


const someId = data.id;
                values.some_id = someId;
                values.updateParams.map(
                    params => params.some_another_id = someId,
                );

In the above code, eslint is throwing some error and won't be able to understand those. Here I added the screenshots of the error.

enter image description here enter image description here


Solution

  • const someId = data.id;
    values.some_id = someId;
    values.updateParams.map(
        params => ({ ...params,  serviceable_port_pair_id: someId,})
    );
    

    you are supposed to return the Object, how it should look like, but not mutate the parameter inside the arrow function

    and for the first error message. The insutructions couldnt be clearer. You shouldnt reassign already defined params