useDispatch is not a function error
See original GitHub issuewhen 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:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please make sure you are using React-Redux v7.1.0.
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') }