Home > Mobile >  Javascript react - using createSlice and encountering 'property assignment expected' / �
Javascript react - using createSlice and encountering 'property assignment expected' / �

Time:06-15

I'm trying for the first time to create a slice using react, and am encountering the following issue. My 'createSlice' looks as follows:

const querySlice = createSlice({
  name: 'querySlice',
  initialState,  
  reducers: {
    setOutputTable: (state, action: PayloadAction<string>) => {
      state.outputTable = action.payload;      
    },
    setInputTable: (state, action: PayloadAction<string>) => {
      state.inputTable = action.payload;      
    },
    setSelectColumns: (state, action: PayloadAction<string>) => {
      state.selectColumns = action.payload;      
    },
    reset() {
      return initialState;
    },
  },  
)};

Using VS Code, the bottom parentheses and curly bracket are marked for error, with the issues being 1) Property assignment expected. 2) Declaration or statement expected.

Does anyone recognize what might be amiss in my code? Thanks for any suggestions.

CodePudding user response:

In your last line, it should be }), not )}

CodePudding user response:

Rewrite:

const querySlice = createSlice({
  name: 'querySlice',
  initialState,  
  reducers: {
    setOutputTable: (state, action: PayloadAction<string>) => {
      state.outputTable = action.payload;      
    },
    setInputTable: (state, action: PayloadAction<string>) => {
      state.inputTable = action.payload;      
    },
    setSelectColumns: (state, action: PayloadAction<string>) => {
      state.selectColumns = action.payload;      
    },
    reset: () => {
      state = initialState;
    },
  },  
)};

  • Related