简体   繁体   English

React Native Debugger 状态未定义

[英]React Native Debugger state undefined

I am trying to use the remote React Native Debugger for my project.我正在尝试为我的项目使用远程 React Native Debugger。 I have installed React-Native-Debugger on my Mac with $ brew update && brew cask install react-native-debugger .我已经使用$ brew update && brew cask install react-native-debugger在我的 Mac 上安装了 React-Native-Debugger。 Then I added Remote-redux-devtools package with npm install --save-dev remote-redux-devtools然后我用npm install --save-dev remote-redux-devtools添加了 Remote-redux-devtools 包

My createStore code looks like this atm.我的 createStore 代码看起来像这个 atm。

import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'remote-redux-devtools'
import thunk from 'redux-thunk'
/* some other imports */

const composeEnhancers = composeWithDevTools({ realtime: true, port: 8000 })
export default createStore(rootReducer, composeEnhancers(
  applyMiddleware(thunk.withExtraArgument(api), logger, firebaseSave)
))

Console output works just fine, but it is not picking up on the actions or redux state.控制台输出工作得很好,但它没有接收操作或 redux 状态。 Am I missing a step?我错过了一步吗? Why isn't it picking up redux?为什么不选择 redux?

https://github.com/zalmoxisus/remote-redux-devtools https://github.com/zalmoxisus/remote-redux-devtools

https://github.com/jhen0409/react-native-debugger https://github.com/jhen0409/react-native-debugger

Here's the solution I used in order to make the redux states visible on the react-native-debugger: Let's suppose That I have a redux reducer called uiReducer :这是我用来使 redux 状态在 react-native-debugger 上可见的解决方案:假设我有一个名为uiReducer的 redux reducer:

const rootReducer = combineReducers({
  ui: uiReducer
});

let composeEnhancers = compose;

if (__DEV__) {
    composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
}

const store = createStore(rootReducer, composeEnhancers(applyMiddleware(ReduxThunk)));

Please don't forget to import your reducer, and also the following imports from redux, react-redux and redux-thunk :请不要忘记导入您的减速器,以及以下来自 redux、react-redux 和 redux-thunk 的导入:

import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
import ReduxThunk from 'redux-thunk';

Now, your state if visible in the debugger :现在,您的状态如果在调试器中可见:

调试器截图

I hope it's helpful !我希望它有帮助! Thanks,谢谢,

Add redux devtools extension to your createStore将 redux devtools 扩展添加到你的 createStore

export default createStore(rootReducer, composeEnhancers(
  applyMiddleware(thunk.withExtraArgument(api), logger, firebaseSave)
),window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())

For more informations : https://github.com/zalmoxisus/redux-devtools-extension更多信息: https : //github.com/zalmoxisus/redux-devtools-extension

I got the same problem where i thought the react native debugger is working fine, Eg react native debugger's mapper is working fine, it is pulling out my project file/directory at the source.我遇到了同样的问题,我认为 react native 调试器工作正常,例如 react native 调试器的映射器工作正常,它正在从源头提取我的项目文件/目录。 Console output is working fine.控制台输出工作正常。

But i don't see any redux being picking up.但我没有看到任何 redux 正在兴起。

After some trials and errors, i found out i have to turn the JS Dev Mode on my android emulator.经过一些试验和错误,我发现我必须在我的 android 模拟器上打开 JS 开发模式。

Steps: Ctrl + M -> Dev Setting -> Check JS Dev Mode -> Reload步骤:Ctrl + M -> Dev Setting -> Check JS Dev Mode -> Reload

I noticed that along with this, I couldn't see my sources in Developer tools which lead me to realise that I need to do this我注意到,与此同时,我无法在开发人员工具中看到我的资源,这让我意识到我需要这样做

On the IOS Simulator在 IOS 模拟器上

Cmd + D > Debug JS Remotely worked for me Cmd + D > 调试 JS 远程为我工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM