[英]Custom ESLint rule for Redux reducers
I am using Redux and Redux Toolkit in combination with ESLint.我将 Redux 和 Redux 工具包与 ESLint 结合使用。
When I implement my extraReducers
, sometimes I don't require both the state
and action
property that Redux supplies, which in turn, makes ESLint throw an error.当我实现我的extraReducers
时,有时我不需要state
和 Redux 提供的action
属性,这反过来又使 ESLint 抛出错误。
Right now, I am manually disabling the linter rule for that specific line with this comment:现在,我正在使用以下注释手动禁用该特定行的 linter 规则:
// eslint-disable-next-line no-unused-vars
However, is there a way to rewrite the function declaration to avoid the linter rule, or can I globally disable the rule only for this case?但是,有没有办法重写 function 声明以避免 linter 规则,或者我可以仅针对这种情况全局禁用规则?
const userSlice = createSlice({
name: "user",
initialState,
reducers: {},
extraReducers: {
// eslint-disable-next-line no-unused-vars
[fetch.pending]: (state, action) => {
state.status = "loading"
},
},
})
You just don't need to declare parameters that you don't use.您只是不需要声明您不使用的参数。 You can always add them in later.您可以随时添加它们。
const userSlice = createSlice({
name: "user",
initialState,
reducers: {},
extraReducers: {
[fetch.pending]: () => {
state.status = "loading"
},
},
})
is totally fine as well.也很好。
In that case you can leave out action
param.在这种情况下,您可以省略action
参数。 But if unused param precedes used ones, then one option is to use underscore syntax , which is quite common practice:但是如果未使用的参数在使用的参数之前,那么一种选择是使用 下划线语法,这是很常见的做法:
const example = (_foo, bar) => console.log(bar);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.