15
votes

I am trying to update my store in redux via useDispatch method, but I am getting a message like that:

Attempted import error: 'useDispatch' is not exported from 'react-redux'.

I am using this method for call the action to update my store.

import { useDispatch } from 'react-redux';
import { loggedInAction } from './redux';

const userInfo = () => {
const dispatch = useDispatch();
const loggedIn = user => dispatch(loggedInAction(user));
5
which version of react-redux are you using?Will Jenkins
it is react-redux v 7.0.3Maciej Kitowski
import {useDispatch} from 'redux-react-hook';msahin

5 Answers

19
votes

Edit (Sept 15, 2019):
Install [email protected] or react-redux@latest

Find latest version here: https://www.npmjs.com/package/react-redux?activeTab=versions


Install react-redux version: 7.1.0-rc.1
or do npm install react-redux@next

3
votes

I just forget to give the curly braces over {useDispatch} and that's why I was facing this error!

1
votes

You need to use v7.1.0, current release candidate is v7.1.0-rc.1

See this page

Note: The hook APIs listed in this page are currently a release candidate! We encourage you to try them out in your applications and give feedback. We hope that the APIs are stable at this point, but be aware that there may still be changes before final release.

These hooks were first added in v7.1.0.

1
votes

You need to install the latest version of react-redux

0
votes

This error is due to the version of react-redux You can solve this problem by using

npm install react-redux@latest

For more information check the github page: check this