2017-04-21 128 views
0

反应视图没有更新(渲染永远不会被调用),但reducer被调用。React View没有用更新的更新

我有以下内容:

1)。该反应的看法:我在根状态字段以威慑如果我需要显示“TodoList的”或“HousingInfo”

export default class RightPane extends React.Component{ 
static contextTypes = { 
    store: React.PropTypes.object 
    } 

render(){ 
    let store = this.context.store; 
    let curPage = store.getState()["mainRightPanePage"].currentPage; 
    return (
     <div> 
      {(store.getState()["mainRightPanePage"].currentPage==="TodoList") && <TodoList/>} 
      {(store.getState()["mainRightPanePage"].currentPage==="HousingInfo") && <HousingInfo/>} 
     </div> 
    ) 
} 

}

2)。动作派发到另一个组件

export default class LeftPane extends React.Component{ 
    static contextTypes = { 
     store: React.PropTypes.object 
     } 
    handleink(pageId, e) { 
     e.preventDefault(); 
     let store = this.context.store; 
     store.dispatch({'type':'switchPage', 'pageId':pageId}); 
    ... 
} 

3)。减速器:调用以下减速器

const mainRightPanePage = (state = {'currentPage':'TodoList'}, action) => { 
    switch (action.type) { 
    case 'switchPage': 
     return Object.assign({}, state, { 
      currentPage: action.pageId 
     }) 
    default: 
    return state 
    } 
} 

export default mainRightPanePage 

我错过了什么?

感谢

+0

你在哪里使用'store.subscribe()'?或者您可以使用react-redux来将商店数据连接到组件 –

回答

3

在您的示例RightPane成分是不知道Redux的状态下进行更新,因为你还没有订阅Redux的状态变化。您可以订阅终极版商店直接使用subscribe方法,也可以使用从React-Reduxconnect方法将设备连接到Redux的店(推荐):