Search code examples
reactjsredux

Expected an assignment or function call Redux action creator


I'm trying a create a full stack login (creating the client UI and logic and the server logic as well) in ASP.NET Core and React and I've integrated Redux state in it: once a user clicks the submit button, the client sends the request to the server and receives something in return. This something is then sent to the redux store (will replace that with cookies later but I will still need redux for other things). But I get this error:

Expected an assignment or function call and instead saw an expression no-unused-expressions

This is my code (error corresponds to the first return line of the action creator (only 1 atm):

export const loginAction = (userName, realName) => {
    return
    {
        type: "LOG_IN_USER",
        userName,
        realName
    }
}

This is my reducer:

const initialState = {
    userName: "",
    fullName: ""
};

export const rootReducer = (state = initialState, action) => {
    switch (action.type) {
        case "LOG_IN_USER": {
            return {
                ...state, // in case I need to add state fields that have nothing to do with user details
                userName: action.userName,
                fullName: action.fullName
            }
        }
        default: return state;
    }
}

My dispatch:

const mapDispatchToProps = (dispatch) => {
    return {
        loggingIn: (userName, realName) => dispatch(loginAction(userName, realName))
    }
}

Solution

  • You need to put your opened bracket { on the same line with the return.

    return {
        type: 'LOG_IN_USER',
        userName,
        realName,
    };