我尝试在(IOS)React Native 项目中使用 Reactotron 调试应用程序,但是当我运行我的应用程序时出现“无活动”。
我使用 react-native 0.55.4、reactotron 2.1.0(在我的 package.json 中相同)
我尝试在(IOS)React Native 项目中使用 Reactotron 调试应用程序,但是当我运行我的应用程序时出现“无活动”。
我使用 react-native 0.55.4、reactotron 2.1.0(在我的 package.json 中相同)
您必须执行以下操作:
adb reverse tcp:9090 tcp:9090
import Reactotron, { asyncStorage } from 'reactotron-react-native';
Reactotron
.configure() // controls connection & communication settings
.useReactNative(asyncStorage()) // add all built-in react native plugins
.connect();
if (__DEV__) {
import('../../lib/Reactotron').then(() => console.log('Reactotron Configured'));
}
注意:如果你host
不想在里面使用Prorperty configure()
,一定要使用127.0.0.1
。在我的情况下,其他 IP(即使像 192.xxx 这样的本地 IP)不起作用。
之后,您的连接应该可以正常工作,并且您可以像文档中描述的那样使用 Reactotron。
暗示:
对于 Linux 和 Mac,您可以将其添加到 package.json(脚本部分)(根据需要调整 reactotron-app 的路径和调用):
"scripts": {
...
"reactotron": "adb reverse tcp:9090 tcp:9090 && /opt/Reactotron/reactotron-app",
...
}
我做了这个adb reverse tcp:9090 tcp:9090
,我从 Suther 那里得到的yarn start --reset-cache
,它奏效了。
首先,您没有将配置的 Reactotron 对象分配给您的 console.tron 值。你需要做这样的事情:
console.tron = Reactotron.configure({ ...
查看您的 reactotronConfig.js 文件,我注意到您将其发送到 localhost。这仅在模拟器上运行时才有效(不确定您是否正在这样做)。
如果你想在设备上运行它,你需要给它你的打包器的 IP 地址。一种简洁的方法是使用以下代码:
import { NativeModules } from 'react-native';
let packagerHostname = "localhost";
if (__DEV__) {
const scriptURL = NativeModules.SourceCode.scriptURL;
packagerHostname = scriptURL.split("://")[1].split(":")[0];
}
const reactotron = Reactotron.configure({
name: "myAPPILOC",
host: packagerHostname
});
console.tron = Reactotron;
请开启调试模式(iOS模拟器按⌘+D,安卓模拟器按⌘+M,或摇动真机)。然后杀死应用程序并重新启动应用程序。
我希望它有帮助
我可以推荐并且对我有用的是安装这些版本包:
"reactotron-react-native": "3.5.0",
"reactotron-redux": "3.1.0",
然后你需要相应地配置你的store
:
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()));
当然,以上是我的设置,但您需要相应地调整您的设置,重点是遵循此处记录的配置: https ://github.com/infinitered/reactotron/blob/master/docs/plugin-redux .md