Reactjs userslice 中的错误 - React Redux Toolkit
Error in Reactjs userslice - React Redux Toolkit
我在创建用户切片时遇到错误,但我不知道如何解决这个问题。这似乎是一个简单的错误,但我没有找到让它工作的方法。
错误
Line 14:7: Expected an assignment or function call and instead saw an
expression no-unused-expressions
Line 19:7: Expected an assignment or function call and instead saw an
expression no-unused-expressions
代码
import { createSlice } from "@reduxjs/toolkit";
const initialUserState = {
fullname: "",
email: "",
isAuth: false
}
const userSlice = createSlice({
name: "user",
initialState: initialUserState,
reducers: {
setUserState: (state, action) => {
state.fullname = action.payload.fullname,
state.email = action.payload.email,
state.isAuth = action.payload.isAuth
},
reset: (state) => {
state.fullname = "",
state.email = "",
state.isAuth = false
},
},
});
export const userActions = userSlice.actions;
export default userSlice.reducer;
第 14 行是 state.fullname = action.payload.fullname
第 19 行是 state.fullname = ""
我很感激我能得到的所有帮助
您的代码违反了 eslint 规则no-unused-expressions。
Note: Sequence expressions (those using a comma, such as a = 1, b = 2
) are always considered unused unless their return value is assigned or a function call is made with the sequence expression value.
尝试将语句末尾的逗号替换为 ;
。
state.fullname = action.payload.fullname,
^
// replace `,` with `;`.
我在创建用户切片时遇到错误,但我不知道如何解决这个问题。这似乎是一个简单的错误,但我没有找到让它工作的方法。
错误
Line 14:7: Expected an assignment or function call and instead saw an
expression no-unused-expressions
Line 19:7: Expected an assignment or function call and instead saw an
expression no-unused-expressions
代码
import { createSlice } from "@reduxjs/toolkit";
const initialUserState = {
fullname: "",
email: "",
isAuth: false
}
const userSlice = createSlice({
name: "user",
initialState: initialUserState,
reducers: {
setUserState: (state, action) => {
state.fullname = action.payload.fullname,
state.email = action.payload.email,
state.isAuth = action.payload.isAuth
},
reset: (state) => {
state.fullname = "",
state.email = "",
state.isAuth = false
},
},
});
export const userActions = userSlice.actions;
export default userSlice.reducer;
第 14 行是 state.fullname = action.payload.fullname
第 19 行是 state.fullname = ""
我很感激我能得到的所有帮助
您的代码违反了 eslint 规则no-unused-expressions。
Note: Sequence expressions (those using a comma, such as
a = 1, b = 2
) are always considered unused unless their return value is assigned or a function call is made with the sequence expression value.
尝试将语句末尾的逗号替换为 ;
。
state.fullname = action.payload.fullname,
^
// replace `,` with `;`.