Home > Mobile >  Error in Reactjs userslice - React Redux Toolkit
Error in Reactjs userslice - React Redux Toolkit

Time:10-19

i´m getting an error when i´m creating my userslice, but i have no clue how to solve this. It seems a simple error but i i´m not finding a way to make it work.

The error

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

Code

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;

Line 14 is state.fullname = action.payload.fullname

Line 19 is state.fullname = ""

I appreciate all the help i can get on this

CodePudding user response:

Your code violated eslint rules 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.

Try to replace the comma at the end of the statement with ;.

state.fullname = action.payload.fullname,
                                        ^ 
                                     // replace `,` with `;`.
  • Related