Reactjs 重复无限循环

Reactjs 重复无限循环,reactjs,redux,react-redux,Reactjs,Redux,React Redux,我有以下代码: const mapStateToProps = state => { return { language: state.language, user: state.user}; }; function mapDispatchToProps(dispatch) { return { initConfig: () => dispatch(initConfig()) }; } 它工作正常,现在我需要添加一些关于ui的信息,为此,我需要映射其他部件对象

我有以下代码:

const mapStateToProps = state => {
  return { language: state.language, user: state.user};
};

function mapDispatchToProps(dispatch) {
  return {
    initConfig: () => dispatch(initConfig())
  };
}
它工作正常,现在我需要添加一些关于ui的信息,为此,我需要映射其他部件对象:

const mapStateToProps = state => {
  return { language: state.language, user: state.user, userSettings: state.userSettings};
};

function mapDispatchToProps(dispatch) {
  return {
    initConfig: () => dispatch(initConfig())
  };
}
如果我添加
userSettings:state.userSettings
应用程序会执行一个无限循环,比如设置会不断更改,组件需要重新加载,但这不是真的,组件仍然保持不变,这是怎么可能的?为什么要重新渲染

这是我的减速机:


const initialState = {
 settings : {
    tags: false,
    userSettings: {
      active_socialization         : 0,
      active_socialization_radius  : 0,
      active_socialization_age_min : 0,
      active_socialization_age_max : 0,
      active_socialization_gender  : '',
      position_visibility          : 0,
      position_label               : '',
      notify_mention_post          : 0,
      notify_mention_photo         : 0,
      notify_new_post_follow       : 0,
      notify_new_post_hot          : 0,
      notify_new_post_moderate     : 0,
      notify_new_post_private      : 0,
      notify_new_post_group        : 0,
      visibility_username          : 0,
      visibility_contact           : 0,
      ui_bkg_type                  : false,
      ui_bkg_image                 : false,
      ui_color_photo               : false,
      ui_color_video               : false,
      ui_color_audio               : false,
      ui_color_minimes             : false,
      ui_color_news                : false,
      ui_color_mix                 : false
    }
};

function rootReducer(state = initialState, action) {

  // LOADING
  if (action.type === "UTILITY_LOADING") {
    console.log('reducer UTILIY_LOADING');
    return { ...state,   utility : { loading : true } }
  }

  // LANGUAGE
  if (action.type === "UTILITY_LANGUAGE") {
    console.log('reducer UTILITY_LANGUAGE');
    console.log(action);
    return { ...state, language : action.payload }
  } 

    // INIT CONFIG
  if (action.type === "INIT_CONFIG_LOADED") {
    return { ...state,  settings : { ...state.settings, tags : action.payload.tags, userSettings : action.payload.userSettings, appSettings : action.payload.appSettings, userRow : action.payload.userRow, avatar : action.payload.avatar } , utility : { loading : false, } }
  } 

  if (action.type === "INIT_CONFIG_NOT_LOADED") {
    return { ...state,   utility : { loading : false } }
  } 

...


你能告诉我们你的userSettings reducer是什么样子吗?你在哪里调用
initConfig()
?它似乎是在某个生命周期方法中调用
initConfig()
。然后,减速机返回一个全新的状态
{…state,…}
。因此,
connect
HOC更新您的组件,并再次调用生命周期方法。。。等等我说得对吗在
状态中没有
userSettings
。userSettings
-试试
state.settings.userSettings
@red这没什么大不了的=)我很乐意帮忙!