javascript - React Native 调试器状态未定义
<p><p>我正在尝试为我的项目使用远程 React Native 调试器。我已经使用 <code>$ brew update && brew cask install react-native-debugger</code> 在我的 Mac 上安装了 React-Native-Debugger。然后我用 <code>npm install --save-dev remote-redux-devtools</code> </p> 添加了 Remote-redux-devtools 包
<p>我的 createStore 代码看起来像这个 atm。</p>
<pre><code>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)
))
</code></pre>
<p>控制台输出工作得很好,但它没有处理操作或 redux 状态。我错过了一步吗?为什么不支持 redux?</p>
<p> <a href="https://github.com/zalmoxisus/remote-redux-devtools" rel="noreferrer noopener nofollow">https://github.com/zalmoxisus/remote-redux-devtools</a> </p>
<p> <a href="https://github.com/jhen0409/react-native-debugger" rel="noreferrer noopener nofollow">https://github.com/jhen0409/react-native-debugger</a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这是我用来使 redux 状态在 react-native-debugger 上可见的解决方案:
假设我有一个名为 <code>uiReducer</code> 的 redux reducer:</p>
<pre><code>const rootReducer = combineReducers({
ui: uiReducer
});
let composeEnhancers = compose;
if (__DEV__) {
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
}
const store = createStore(rootReducer, composeEnhancers(applyMiddleware(ReduxThunk)));
</code></pre>
<p>请不要忘记导入你的 reducer,以及从 redux、react-redux 和 redux-thunk 导入的以下内容:</p>
<pre><code>import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
import ReduxThunk from 'redux-thunk';
</code></pre>
<p>现在,您的状态(如果在调试器中可见):</p>
<p> <a href="/image/3ULRx.png" rel="noreferrer noopener nofollow"><img src="/image/3ULRx.png" alt="debugger screenshot"/></a> </p>
<p>希望对你有帮助!
谢谢,</p></p>
<p style="font-size: 20px;">关于javascript - React Native 调试器状态未定义,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46828816/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46828816/
</a>
</p>
页:
[1]