question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useDispatch is not a function error

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

18reactions
markeriksoncommented, Jun 21, 2019

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

2reactions
AhrenFullStopcommented, Mar 16, 2021

still an issue for me on V7.2.2

const dispatch = useDispatch() const Register = useSelector(state => state.auth) const onSubmit = () => { if (email && firstName && lastName && mobileNumber) { dispatch(RegisterUsers(firstName, lastName, email, mobileNumber, referalCode)) setError(""); if (Register.authorized === true) { //do stuff } } else { setError("Enter all your details") } props.navigation.navigate('interest') }

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactRedux.useDispatch is not a function - Stack Overflow
I am trying to use react-redux hooks, however I get the error: TypeError: (0 , _reactRedux.useDispatch) is not a function. Any ideas?
Read more >
Hooks - React Redux
Hooks. React's new "hooks" APIs give function components the ability to use local component state, execute side effects, and more.
Read more >
react-usedispatch-typeerror-object-is-not-a-function ...
CodeSandbox is an online editor tailored for web applications.
Read more >
React-redux useDispatch() Uncaught TypeError-Reactjs
Coding example for the question React-redux useDispatch() Uncaught TypeError-Reactjs. ... _ColorReducer.color) is not a function error in React + Redux code ...
Read more >
React-Redux testing: mocking useSelector and useDispatch
Testing whether or not useDispatch has been called it('does something', () => { // ARRANGE const dummyDispatch = jest.fn() useDispatchMock.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found