简体   繁体   English

为什么我仍然无法阅读未定义的地图?

[英]Why am i still getting cannot read map of undefined?

Running redux sagas and react together and totally stumped why i'm still getting undefined errors. 运行redux sagas并一起做出反应,完全卡住了为什么我仍然遇到未定义的错误。 I have an initial state set so that .map can just run on that, i've tried null, undefined, empty arrays - always the same error. 我设置了一个初始状态,以便.map可以在其上运行,我尝试了null,未定义,空数组-始终是相同的错误。

Where am I going wrong, guys & gals? 伙计们,我哪里出问题了?

App.js App.js

    {
      isFetching ? (
        <button disabled>Fetching...</button>
      )
      :
      <div>
        <button onClick={onRequest}>Click For API Names</button>
        <ul>
          {users.map((each, i) => <li key={i}>{each.name}</li>)}
        </ul>
      </div>
    };

...
const mapStateToProps = state => {
  return {
    isFetching: state.isFetching,
    users: state.users,
    error: state.error,
  };
};

const mapDispatchToProps = dispatch => {
  return {
    onRequest: () => dispatch({ type: constants.API_REQUEST }),
  };
};

reducer.js reducer.js

const initialState = {
  isFetching: false,
  users: [{ name: '' }, { name: '' }],
  error: null,
};

export const namesReducer = (state = initialState, action) => {
  switch(action.type) {
    case constants.API_REQUEST:
      return {
        ...state,
        isFetching: true,
        error: null,
      };
    case constants.API_SUCCESS:
      return {
        ...state,
        isFetching: false,
        users: action.payload,
        error: null,
      };
    case constants.API_FAILURE:
      return {
        ...state,
        isFetching: false,
        users: [''],
        error: action.error,
      };
    default:
      return state;
  };
}

users: action.payload 用户:action.payload

action payload probably isn't an array 动作有效负载可能不是数组

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试访问嵌入的Google地图时,为什么会出现无法读取未定义的属性“ getCenter”的问题? - Why am I getting Cannot read property 'getCenter' of undefined when trying to access my embed google map? 为什么我收到错误:类型错误:无法读取未定义的属性“地图”? - Why am I getting an error : TypeError: Cannot read property 'map' of undefined? 我为什么会收到TypeError:无法读取未定义的属性“现在” - Why am I getting TypeError: Cannot read property 'now' of undefined 为什么我在此 for 循环中无法读取未定义的属性“startsWith”? - Why am I getting Cannot read property 'startsWith' of undefined in this for loop? 为什么会出现“无法读取未定义的html属性”? - Why am I getting “Cannot read property of html undefined”? 为什么我越来越无法读取未定义错误的属性? - why I am getting, cannot read property of undefined error? 为什么在此示例中出现“无法读取未定义的属性&#39;文本&#39;”? - Why am I getting “Cannot read property 'text' of undefined” in this example? 为什么我收到“ TypeError:无法读取未定义的属性” length” - Why am I getting 'TypeError: Cannot read property 'length' of undefined' 为什么我得到这个“无法读取未定义的属性”长度”? (JavaScript) - Why am I getting this 'cannot read property 'length' of undefined'? (JavaScript) 为什么我会收到未定义的 map 的 TypeError? - why am i getting a TypeError of undefined map?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM