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
Please make sure you are using React-Redux v7.1.0.
no this is v6. I will update. thank you
Most helpful comment
Please make sure you are using React-Redux v7.1.0.