Here is the reducer, the RemoveField function is removing the last element from the number of fields array instead of the passed index
const UiReducer = createSlice({
name: 'ui',
initialState: {
name: 'User',
numberOfFields: [0],
numberOfSubFields: [0],
},
reducers: {
setName(state, action) {
state.name = action.payload;
},
AddField(state, action) {
state.numberOfFields = [...state.numberOfFields, action.payload];
},
RemoveField(state, action) {
console.log(action.payload);
state.numberOfFields.splice(action.payload, 1);
},
},
});