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

Viewed 22707

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 Answers

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

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.

You need to install the latest version of react-redux

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

Related