Reactjs PropType失败。值未定义

Reactjs PropType失败。值未定义,reactjs,redux,react-router,react-redux,react-slingshot,Reactjs,Redux,React Router,React Redux,React Slingshot,我的意图是做一些非常基本的事情。我只想在渲染时将我的名字显示在HelloPage容器中,然后单击将我的名字转换为“Bob”。我想我遗漏了一些愚蠢的东西 HelloPage.js(容器,我的名字应该出现在这里,但完全没有定义) 这是我设置initialState文件的方式: export default { hello: { name: 'Gabriel' } }; 还有,我组合减速器的方式: import { combineReducers } from 'redux'; im

我的意图是做一些非常基本的事情。我只想在渲染时将我的名字显示在HelloPage容器中,然后单击将我的名字转换为“Bob”。我想我遗漏了一些愚蠢的东西

HelloPage.js(容器,我的名字应该出现在这里,但完全没有定义)

这是我设置initialState文件的方式:

export default {
  hello: {
    name: 'Gabriel'
  }
};
还有,我组合减速器的方式:

import { combineReducers } from 'redux';
import fuelSavings from './fuelSavingsReducer';
import hello from './helloReducer';
import {routerReducer} from 'react-router-redux';

const rootReducer = combineReducers({
  fuelSavings,
  hello,
  routing: routerReducer
});

export default rootReducer;

应用程序的其他容器/组件工作正常,但只有这个新容器不工作。我用的是react。刚刚增加了一条额外的路线。我复制了样板文件中的结构。

在对象“hello”的第二级定义了“name”的初始状态

因此,要访问它,您需要将mapStateToProps函数更改为:

function mapStateToProps(state) { 
  return { 
   name: state.hello.name 
  };
}

尝试将
函数mapstatetops(state){return{name:state.name};}
更改为
函数mapstatetops(state){return{name:state.hello.name};}
@HardikJain好的,现在它可以工作了。谢谢(请随意复制并粘贴到答案中。)
import { combineReducers } from 'redux';
import fuelSavings from './fuelSavingsReducer';
import hello from './helloReducer';
import {routerReducer} from 'react-router-redux';

const rootReducer = combineReducers({
  fuelSavings,
  hello,
  routing: routerReducer
});

export default rootReducer;
function mapStateToProps(state) { 
  return { 
   name: state.hello.name 
  };
}