簡體   English   中英

React Native Debugger 狀態未定義

[英]React Native Debugger state undefined

我正在嘗試為我的項目使用遠程 React Native Debugger。 我已經使用$ brew update && brew cask install react-native-debugger在我的 Mac 上安裝了 React-Native-Debugger。 然后我用npm install --save-dev remote-redux-devtools添加了 Remote-redux-devtools 包

我的 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)
))

控制台輸出工作得很好,但它沒有接收操作或 redux 狀態。 我錯過了一步嗎? 為什么不選擇 redux?

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

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

這是我用來使 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)));

請不要忘記導入您的減速器,以及以下來自 redux、react-redux 和 redux-thunk 的導入:

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

現在,您的狀態如果在調試器中可見:

調試器截圖

我希望它有幫助! 謝謝,

將 redux devtools 擴展添加到你的 createStore

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

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

我遇到了同樣的問題,我認為 react native 調試器工作正常,例如 react native 調試器的映射器工作正常,它正在從源頭提取我的項目文件/目錄。 控制台輸出工作正常。

但我沒有看到任何 redux 正在興起。

經過一些試驗和錯誤,我發現我必須在我的 android 模擬器上打開 JS 開發模式。

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

我注意到,與此同時,我無法在開發人員工具中看到我的資源,這讓我意識到我需要這樣做

在 IOS 模擬器上

Cmd + D > 調試 JS 遠程為我工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM