reactjs - reactRedux.useDispatch 不是函数

标签 reactjs redux react-redux react-hooks

我正在尝试使用 react-redux 钩子(Hook),但是我得到了错误:

TypeError: (0 , _reactRedux.useDispatch) is not a function

有什么想法吗?

...
import { useDispatch, useSelector } from "react-redux";
import { StackActions, NavigationActions } from "react-navigation";
import CustomImage from "./CustomImage";

const VideoEpisode = props => {
  const { id, title, description, video, preview, push, testLink } = props;
  const dispatch = useDispatch();
  return (
    <TouchableHighlight
      ....
      onPress={() => {
        const resetAction = StackActions.reset({
          ...
        });
        dispatch(resetAction);
      }}
    >
      ...
    </TouchableHighlight>
  );
};

export default VideoEpisode;

包.json

{
  "name": "iaapp",
  "version": "0.0.1",
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "name": "Innovative Anatomy",
    "flow": "flow",
    "test": "node ./node_modules/jest/bin/jest.js --watchAll"
  },
  "jest": {
    "preset": "react-native"
  },
  "dependencies": {
    "@babel/plugin-proposal-decorators": "^7.4.4",
    "@babel/runtime": "^7.0.0",
    "@react-native-community/async-storage": "^1.6.1",
    "react": "16.8.5",
    "react-dom": "^16.8.6",
    "react-native": "0.59.10",
    "react-native-circular-progress": "^1.1.0",
    "react-native-component-fade": "^1.0.2",
    "react-native-elements": "^1.1.0",
    "react-native-fade": "^1.0.3",
    "react-native-fade-in-view": "^1.0.5",
    "react-native-gesture-handler": "^1.1.0",
    "react-native-responsive-image": "^2.3.1",
    "react-native-share": "^1.2.1",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^9.5.1",
    "react-native-vector-icons": "^6.6.0",
    "react-native-view-shot": "^2.6.0",
    "react-native-webview": "^5.12.1",
    "react-native-webview-bridge": "^0.40.1",
    "react-navigation": "^3.0.9",
    "react-navigation-backhandler": "^1.3.2",
    "react-navigation-transitions": "^1.0.11",
    "react-redux": "^7.1.0",
    "redux": "^4.0.1",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.5.5",
    "@babel/core": "^7.5.5",
    "@babel/preset-flow": "^7.0.0",
    "jest": "^24.8.0",
    "metro-react-native-babel-preset": "^0.54.1",
    "prettier": "^1.18.2",
    "react-native-dotenv": "^0.2.0",
    "redux-logger": "^3.0.6"
  },
  "rnpm": {
    "assets": [
      "./assets/fonts"
    ]
  },
  "private": true
}

最佳答案

我在使用 react.createcontext 时遇到了类似的问题,唯一似乎有效的方法是删除 node_modules 文件夹并重新安装它们 (npm install)。

只需确保您的 package.json 配置正确

关于reactjs - reactRedux.useDispatch 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60546012/

相关文章:

javascript - React View 只能在页面重新加载时获取最新数据?

javascript - 警告 : setState(. ..):在 React Redux 中现有状态转换期间无法更新

javascript - 使用 API 调用更新 React-Redux 中的组件状态

javascript - 如何在 React 组件中间隔旋转 <img> 源?

javascript - 是否有从对象渲染组件的方法? - react

flutter - 如何使用 async_redux 实现路由导航

reactjs - 为什么函数从不调用 redux thunk

javascript - KeyboardDatePicker素材ui的语言怎么改?

reactjs - 我试图了解 react useEffect Hook

javascript - redux-thunk 的唯一好处是什么?