2016-06-11 41 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

相关问题