2016-11-26 207 views
0

我減速機:陣營分量不重渲染連接()

export default function summary(state = { 
    "summary":null 
}, action = null) { 
    switch (action.type) { 

    case GET_SUMMARY_REQUEST_SUCCESS: 
     const newState = Object.assign({}, state); 
     newState.summary = action.data; 
     return newState; 
     break; 
    case GET_SUMMARY_REQUEST_ERROR: 
     return Object.assign({}, state, { 
      sumary:null 
     }); 
     break; 

    default: return state; 
    } 
}; 

根減速機:

import summary from './Summary.js' 
const rootReducer = combineReducers({ 
    summary 
}); 

在我的部分,我使用連接映射狀態道具> 我的組件渲染功能是這樣的:

render() { 
    const summary = this.props.summaryContent || []; 
     return (
      <div className={cx(styles['loading'])} > 
       <Loader width="4" /> 
       {"Loading\u2026"} 
      </div> 
     ); 
} 

function mapStateToProps(state, ownParams) { 
    return { 
     summaryContent: state.summary 
    }; 
} 

export default connect(mapStateToProps)(Summary); 

在componentWillMount,我指派給UPD動作總結在州內吃。現在,我的componentWillReceiveProps向我展示了摘要中的更新狀態,但該組件未呈現。

回答

0

我在這裏可以看到幾個問題:

  1. 您使用summary既作爲減速鍵,在你的減速狀態的指標。這意味着summaryContent應該映射到state.summary.summary。 (雖然我建議將其改爲採用較少混淆的命名約定。)
  2. 您的渲染功能不會以任何有用的方式利用this.props.summaryContent。它只是將它分配給一個變量,然後返回一個加載輸出。
  3. 您在GET_SUMMARY_REQUEST_ERROR的案例中拼寫錯誤summary

我強烈建議配置ESLint,它會提醒您像未使用和拼寫錯誤的變量的問題。