首页 > 解决方案 > React Native:_reactotronReactNative2.default.createStore 不是函数

问题描述

在我的 React Native 应用程序中,我无法让 Reactotron 工作,这意味着它无法连接到我的应用程序。该应用程序确实有 "reactotron-react-native": "1.14.0", "reactotron-redux": "1.13.0",

我分别升级到"reactotron-react-native": "^3.5.0",and"reactotron-redux": "^3.1.0"我的应用程序坏了,但现在它正在连接到 Reactotron UI:

在此处输入图像描述

Reactotron 本身告诉我问题出在App.js文件的第 53 行,这是下面的最后一行代码:

//eslint-disable-next-line
console.ignoredYellowBox = ["Setting a timer"];
import './ReactotronConfig';
import React, {PureComponent} from 'react';
import {
  StyleSheet,
  View,
  StatusBar,
  Linking,
  Platform,
  Alert,
} from 'react-native';
import {applyMiddleware, compose, combineReducers} from 'redux';
import {Provider} from 'react-redux';
import thunkMiddleware from 'redux-thunk';
import Reactotron from 'reactotron-react-native';
import logger from 'logger';
import OneSignal from 'react-native-onesignal';
import SplashScreen from 'react-native-splash-screen';
import {Sentry} from 'react-native-sentry';
import {
  setJSExceptionHandler,
  setNativeExceptionHandler,
} from 'react-native-exception-handler';
import {jsHandler, nativeHandler} from 'utils/error-handlers';

import RootNavigation from 'navigation/RootNavigation';
import LocalStorage from 'services/LocalStorage';
import reducers from 'reducers';
import {
  setCurrentUser,
  validateUserInformationForVoterVoice,
} from 'auth/loginActions';
import {handleEventsDeepLink} from 'events/actions';
import {handleBallotsDeepLink} from 'surveys-ballots/actions';
import {setResetPasswordKey} from 'auth/registrationActions';
import {setNotificationData, deepLinkReceived} from 'navigation/actions';
import {view} from 'utils/view';
import {v2Colors} from 'theme';
import env from 'env';
import base from 'base-endpoint';
import * as appcenter from 'utils/appcenterLogger';
import * as cache from 'utils/cache';
import * as regex from 'utils/helpers/regex';

const appReducer = combineReducers({
  ...reducers,
});
const middleware = applyMiddleware(thunkMiddleware);
//react-native-debugger config
// eslint-disable-next-line no-underscore-dangle
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = Reactotron.createStore(appReducer, composeEnhancers(middleware));

我刚刚熟悉了 Reactotron 的存在,它看起来是一种有效的调试工具,我想知道是否有人正在使用"reactotron-react-native": "^3.5.0",并且"reactotron-redux": "^3.1.0"可能知道第 53 行发生了什么?

我假设它需要像大多数 React Native 重大更改一样进行重构,但我还没有找到任何有关如何配置的文档store,如果该行不再需要的话。

标签: reactjsreact-nativereactotron

解决方案


根据文档: https ://github.com/infinitered/reactotron/blob/master/docs/plugin-redux.md

我必须确保我已经createStore像这样导入了:

import {createStore, applyMiddleware, compose, combineReducers} from 'redux';

然后像这样重构商店:

const appReducer = combineReducers({
  ...reducers,
});
const middleware = applyMiddleware(thunkMiddleware);
//react-native-debugger config
// eslint-disable-next-line no-underscore-dangle
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
// const store = Reactotron.createStore(appReducer, composeEnhancers(middleware));
const store = createStore(appReducer, composeEnhancers(middleware, Reactotron.createEnhancer()));

推荐阅读