【问题标题】:React Native : No store found. Make sure to follow these instructionsReact Native:找不到商店。确保遵循这些说明
【发布时间】:2021-04-05 16:39:34
【问题描述】:

我不明白: 我有一个商店,我已经安装了 redux-devtools-extension 来跟踪我的树商店。

但是 devtool 在我的 react native 应用中找不到我的商店。

import { createStore, combineReducers, applyMiddleware } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import authReducer from './store/reducers/auth';

const rootReducer = combineReducers({
  auth: authReducer,
})

const store = createStore(rootReducer, {}, composeWithDevTools(
  applyMiddleware(ReduxThunk),
));

这是我的包版本:

"react-native-debugger-open": "^0.3.25",
"redux-devtools-extension": "^2.13.9",
"react-redux": "^7.2.3",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"

我不明白问题出在哪里。

你能帮帮我吗?

【问题讨论】:

  • 您是否将您的应用程序包装在 react-redux Provider 组件中?
  • 是的!我在我的应用程序中做到了。在我的应用中添加商店工作。只是我在调试器上看不到它
  • 你的组件连接到商店了吗?
  • @docmurloc 是的,我做到了。我在我的组件中使用我的商店。但是,“将您的组件连接到商店”是什么意思?

标签: reactjs react-native debugging redux react-redux


【解决方案1】:

您忘记导出您的商店。试试下面的步骤

第 1 步: 创建商店

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

import profile from '../reducers/profile';

const rootReducer = combineReducers({
  user: profile
});

const configureStore = () => {
  return createStore(
    rootReducer,
    compose(applyMiddleware(thunk))
  );
};

export default configureStore;

第 2 步:index.js 中连接您的商店

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import configureStore from './store';
import App from './App';
import * as serviceWorker from './serviceWorker';

const store = configureStore();

ReactDOM.render(
  <React.StrictMode>
    <Provider store={store}>
      <App />
    </Provider>
  </React.StrictMode>,
  document.getElementById('root')
);

serviceWorker.unregister();

第 3 步: 如下所示在组件内连接商店,

import React, { Component } from 'react';
import { connect } from 'react-redux';

export class Home extends Component {
  render() {
    console.log(this.props.profile)
    return (
      <div className="row">
      <div> Welcome to React-Redux
      </div>
    )
  }
}

const mapStateToProps = (state) => {
  return {
    profile: state.user.profile
  }
}

export default connect(mapStateToProps)(Home);

Complete Source Code with React-Redux and DEMO

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    相关资源
    最近更新 更多