Are the reducers really pure functions when using lastId or

I’m finishing the Redux course and i need your help to understand properly some things about reducers and pure functions.

My English is not good but i will try it:

In the section “Redux Fundamentals” we learned that reducers in Redux are pure functions. we saw too that pure functions always produce the same result for the same arguments.

However, we wrote the next code to build a reducer:

let lastId = 0;

function reducer(state, action) {

  if(action.type === 'bugAdded')
  return [
      id: ++lastId,
      description: action.payload.description,
      resolved: false

In this case we are implementing our business logic in the reduce and we increment the value of lastId.

But we is not getting this variable (lastId) from the reducer arguments or hardcoding this value. This value is supplied from an upper scope. So then this reducer is not really a pure function. it could returns different results with the same arguments because it’s depending on a external value. Right?

I continued with the course thinking that we just was making a minor exception until to build the backend, because this backend should will supply us this value after the bug is added.

But now, I just found another similar case again.

when we are implementing the reducers with Redux Toolkit and createSlice, we type:

const slice = createSlice({
  name: "bugs",
  initialState: {
    list: [],
    loading: false,
    lastFetch: null

  reducers: {
    bugsReceived: (bugs, action) => {
      bugs.list = action.payload;
      bugs.loading = false;
      bugs.lastFetch =;

Again, with; we are assigning a value in our reducer from an unpredictable source.

What am I missing here? i would like to understand about this issue. Can you help me, please?

Thank you.