React-redux: useDispatch is not a function error

Created on 21 Jun 2019  路  2Comments  路  Source: reduxjs/react-redux

when I import useDispatch as the example below in https://react-redux.js.org/next/api/hooks , it displayed an error.

Uncaught (in promise) TypeError: (0 , _reactRedux.useDispatch) is not a function.

import { bindActionCreators } from 'redux'
import { useDispatch } from 'react-redux'
import { useMemo } from 'react'

export function useActions(actions, deps) {
  const dispatch = useDispatch()
  return useMemo(() => {
    if (Array.isArray(actions)) {
      return actions.map(a => bindActionCreators(a, dispatch))
    }
    return bindActionCreators(actions, dispatch)
  }, deps ? [dispatch, ...deps] : [dispatch])
}

In my code

const dispatch = useDispatch()
                const incrementCounter = useCallback(
                    () => dispatch({ type: 'DRIVERS_LIST', payload: data.data.drivers }),
                    [dispatch]
                )

Can someone please explain the reason. @timdorr

Most helpful comment

Please make sure you are using React-Redux v7.1.0.

All 2 comments

Please make sure you are using React-Redux v7.1.0.

no this is v6. I will update. thank you

Was this page helpful?
0 / 5 - 0 ratings