react-template
react-template copied to clipboard
ESLint rule 'no-param-reassign' and Redux Toolkit
ESLInt warns about reassigning state in createSlice()
const langSlice = createSlice({
name: 'language',
initialState,
reducers: {
setLanguage (state, action) {
state.currentLang = action.payload; // Error!
},
},
});
Suggestion: add rule as mentioned in RTK docs https://redux-toolkit.js.org/usage/immer-reducers#linting-state-mutations
{
'no-param-reassign': ['error', { props: true, ignorePropertyModificationsFor: ['state'] }]
}