简体   繁体   English

State 没有加载到我的基本 React/Redux 应用程序中

[英]State is not loading in my basic React/Redux App

I am working on the basic project from the Redux Documenation page.我正在从事 Redux 文档页面中的基本项目。 I am unsure the best way to put a redux project on Stack Overflow, so I instead uploaded my current progress to my GitHub page: https://github.com/davidreke/reduxDocumentationProject我不确定将 redux 项目放在 Stack Overflow 上的最佳方式,所以我将我当前的进度上传到我的 GitHub 页面: https://github.com/davidreke/reduxDocumentationProject

I finished the instructions on setting up my reducers/store/action creators/ etc and got to the section of this page (h ttps://redux.js.org/basics/store ) that says我完成了关于设置我的 reducers/store/action creators/ 等的说明,并进入了这个页面的部分 (h ttps://redux.js.org/basics/store ) 说

Now that we have created a store, let's verify our program works, Even without any UI.现在我们已经创建了一个商店,让我们验证我们的程序是否有效,即使没有任何 UI。 we can already test the update logic.我们已经可以测试更新逻辑了。

However, when I tried making a blank page, I don't see any the console.logs that I have coded into store.js in my app folder, and I am unable to console.log(store.getState()).但是,当我尝试制作一个空白页面时,我没有看到我在我的应用程序文件夹中编码到 store.js 中的任何 console.logs,并且我无法 console.log(store.getState())。 When I open up the Redux dev tool, I also see in there that there is no state. What am I doing wrong that no state loads in my application?当我打开 Redux 开发工具时,我还看到那里没有 state。我的应用程序中没有加载 state 是我做错了什么?

Edit: I've also never asked a question about an application that involves reduce and/or so many files, so if there is a better way for me to present my question, please let me know!编辑:我也从来没有问过有关涉及减少和/或这么多文件的应用程序的问题,所以如果有更好的方式让我提出我的问题,请告诉我!

You are not using the store.您没有使用商店。 In your App.js file import store and Provider then pass the store to the provider.在您的App.js文件中导入商店和提供者,然后将商店传递给提供者。

export store from store.jsstore.js导出商店

export const store = createStore(todoApp)
// you can also add the store to the window object
// and use the console to play around with the data
//window.store = store

Then import store in your App.js然后在你的 App.js 中导入商店

import React from 'react';
import './App.css';

import {
  Provider
} from 'react-redux';

import { store } from './app/store';

function App() {
  return (
    <Provider store={store}>
    <p>test</p>
    </Provider>
  );
}

export default App;

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

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