Search code examples
reactjsreduxredux-toolkit

CreateSlice Error Uncaught ReferenceError: returnfalse is not defined


I have used Redux Toolkit several times before and have never been this error when creating a slice.

const initialState = {
  value : 0
}

export const counteSlice = createSlice({
    name: 'counter',
    initialState, 
    reducers: {
       increment: (state, action) => {
                 state.value += 1
             }
    }

})

The error occured at initialState.

initialState: 0

or

function setInitialState() {
return {
value: 0
   }
}

....slice
initialState: () => setInitialstate
....

are fine.But these are not correct ways to use toolkit I think.

The error says, returnfalse is not defined


Solution

  • The problem is caused by the webpack version. I used webpack v.4.22, but it was solved once I downgraded to v.4.21. (Upgrade is better)

    I found this when I'm trying to use styled component and there was same error. I found solution at https://github.com/styleguidist/react-styleguidist/issues/1181