2016-06-11 39 views
0

我遇到了這個問題,正在調度動作,正在執行reducer,但渲染函數沒有被觸發。React在Redux動作發出後沒有觸發原生渲染

集裝箱:

import React, { Component } from 'react'; 
import { bindActionCreators } from 'redux'; 
import { connect } from 'react-redux'; 
import { renderVoterSearch } from '../actions'; 
import Search from '../components/Search'; 

class SearchContainer extends Component { 
    render() { 
     return (
      <Search {...this.props}/> 
     ); 
    } 
} 

const mapStateToProps = (state) => { 
    return { 
     searchType: state.searchType, 
     instruction: state.instruction, 
     title: state.title 
    } 
} 

const mapDispatchToProps = (dispatch) => { 
    return bindActionCreators({ 
     renderVoterSearch 
    }, dispatch); 
} 

export default connect(mapStateToProps, mapDispatchToProps)(SearchContainer); 

行動從搜索組件調度

export const renderVoterSearch = (tab) => ({ 
    type: RENDER_VOTER_SEARCH, 
    searchType: tab.type, 
    instruction: tab.instruction, 
    title: tab.title 
}); 

減速機:

const search = (state = initialState, action) => { 
    switch (action.type) { 
     case RENDER_VOTER_SEARCH: 
      return { 
       ...state, 
       searchType: action.searchType, 
       instruction: action.instruction, 
       title: action.title 
      } 
     default: 
      return state 
    } 
} 

下面是完整的代碼 https://github.com/mivotico/mivotico-react-native/tree/redux-first-steps/app

我一直在閱讀的原因之一可能是國家正在發生突變,但已經檢查並沒有看到任何突變。

在此先感謝!

回答

0

發現問題!是我不知道減速器是在狀態,所以如果減速器被稱爲「搜索」,那麼在mapStateToProps功能訪問此狀態應該是state.search而不是隻有state

相關問題