{"action":"created","issue":{"url":"https://api.github.com/repos/reactjs/redux/issues/2010","repository_url":"https://api.github.com/repos/reactjs/redux","labels_url":"https://api.github.com/repos/reactjs/redux/issues/2010/labels{/name}","comments_url":"https://api.github.com/repos/reactjs/redux/issues/2010/comments","events_url":"https://api.github.com/repos/reactjs/redux/issues/2010/events","html_url":"https://github.com/reactjs/redux/issues/2010","id":180800469,"number":2010,"title":"How to resolve [Uncaught Error: Reducer returned undefined when handling action.]?","user":{"login":"Crygar","id":17195992,"avatar_url":"https://avatars.githubusercontent.com/u/17195992?v=3","gravatar_id":"","url":"https://api.github.com/users/Crygar","html_url":"https://github.com/Crygar","followers_url":"https://api.github.com/users/Crygar/followers","following_url":"https://api.github.com/users/Crygar/following{/other_user}","gists_url":"https://api.github.com/users/Crygar/gists{/gist_id}","starred_url":"https://api.github.com/users/Crygar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Crygar/subscriptions","organizations_url":"https://api.github.com/users/Crygar/orgs","repos_url":"https://api.github.com/users/Crygar/repos","events_url":"https://api.github.com/users/Crygar/events{/privacy}","received_events_url":"https://api.github.com/users/Crygar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-04T03:53:52Z","updated_at":"2016-10-04T04:23:26Z","closed_at":"2016-10-04T03:59:06Z","body":"Hello, everyone!\r\nI'm a beginner of React, Redux and GitHub. I'm doing practice with React + Router + Redux + ImmutableJS. Everything works well until I'm trying to pass array data from one component to another component which use Material-UI grid to show contents in array. And I got this error message with my project.\r\n\r\n> Uncaught Error: Reducer \"ui\" returned undefined when handling \"CHANGE_ALL_PREVIEW_GOODS\" action. To ignore an action, you must explicitly return the previous state.\r\n\r\n \r\n\r\nI know this question had posted by #1378 and #1375. Thanks to these posts , I realized what the error message means literally. But I don't know how to resolve this problem. I can't realize what wrong with my code. Can anyone tell me how to resolve it?\r\n\r\nFollowing are parts of my project.\r\n```javascript\r\n//Actions\r\nimport { createAction } from 'redux-actions';\r\nimport {\r\n　　CHANGE_ALL_PREVIEW_GOODS,\r\n\tSHOW_ALL_GOODS,\r\n} from '../constants/actionTypes';\r\n\r\nexport const showItemPicture = (imgSrc) => ({ type: SHOW_ITEM_PICTURE, payload: { imgSrc: imgSrc } });\r\nexport const changeAllPreviewGoods = (data) => ({ type: CHANGE_ALL_PREVIEW_GOODS, payload: { data: data } });\r\n```\r\n\r\n```javascript\r\n//Reducers\r\nimport { handleActions } from 'redux-actions';\r\nimport { UiState } from '../../constants/models';\r\n\r\nimport {\r\n  SHOW_ITEM_PICTURE,\r\n  CHANGE_ALL_PREVIEW_GOODS,\r\n} from '../../constants/actionTypes';\r\n\r\nconst uiReducers = handleActions({\r\n  SHOW_ITEM_PICTURE: (state, {payload} ) => (\r\n    state.merge({\r\n      'imgSrc': payload.imgSrc,\r\n    })\r\n  ),\r\n  CHANGE_ALL_PREVIEW_GOODS: (state, {payload} ) => {\r\n    state.merge({\r\n      data: payload.data,\r\n    })\r\n  },\r\n}, UiState);\r\n\r\nexport default uiReducers;\r\n```\r\n```javascript\r\nimport { combineReducers } from 'redux-immutable';\r\nimport ui from './ui/uiReducers';// import routes from './routes';\r\n\r\nconst rootReducer = combineReducers({\r\n  ui,\r\n});\r\nexport default rootReducer;\r\n```\r\n```javascript\r\n//Store\r\nimport { createStore, applyMiddleware } from 'redux';\r\nimport reduxThunk from 'redux-thunk';\r\nimport createLogger from 'redux-logger';\r\nimport Immutable from 'immutable';\r\nimport rootReducer from '../reducers';\r\n\r\nconst initialState = Immutable.Map();\r\n\r\nexport default createStore(\r\n  rootReducer,\r\n  initialState,\r\n  applyMiddleware(reduxThunk, createLogger({ stateTransformer: state => state.toJS() }))\r\n);\r\n```\r\n```javascript\r\n//Containers - SofaPage\r\nimport { connect } from 'react-redux';\r\nimport SofaPage from '../../components/SofaPage';\r\n\r\nimport {\r\n  showItemPicture,\r\n  changeAllPreviewGoods,\r\n} from '../../actions';\r\n\r\nexport default connect(\r\n  (state) => ({\r\n    imgSrc: state.getIn(['ui', 'imgSrc']),\r\n  }),\r\n  (dispatch) => ({\r\n    onShowItemPicture: (src) => (\r\n      dispatch(showItemPicture(src))\r\n    ),\r\n    onChangeAllPreviewGoods: (GoodsData) => (\r\n      dispatch(changeAllPreviewGoods(GoodsData))\r\n    ),\r\n  }),\r\n  (stateProps, dispatchProps, ownProps) => {\r\n    const { imgSrc } = stateProps;\r\n    const { onChangeAllPreviewGoods } = dispatchProps;\r\n    return Object.assign({}, stateProps, dispatchProps, ownProps);\r\n  }\r\n)(SofaPage);\r\n```\r\n```javascript\r\n//Containers - GoodsPage\r\nimport { connect } from 'react-redux';\r\nimport GoodsPage from '../../components/GoodsPage';\r\n\r\nexport default connect(\r\n  (state) => ({\r\n    data: state.getIn(['ui', 'data']),\r\n  }),\r\n  (dispatch) => ({\r\n\r\n  })\r\n)(GoodsPage);\r\n```\r\n```javascript\r\n//Constants - GoodsData\r\nconst sofaOneTilesData = [\r\n  {\r\n    img: 'img/sofa/goods/1_1.jpg',\r\n    title: 'L style',\r\n    author: 'Ben',\r\n    featured: true,\r\n  },\r\n  {\r\n    img: 'img/sofa/goods/1_2.jpg',\r\n    title: 'Flat style',\r\n    author: 'Arya',\r\n  },\r\n  {\r\n    img: 'img/sofa/goods/1_3.jpg',\r\n    title: 'Geometric style',\r\n    author: 'Takeo',\r\n  },\r\n];\r\n\r\nexport default sofaOneTilesData;\r\n```\r\n\r\n```javascript\r\n//Components - sofaPage.js\r\nimport React from 'react';\r\nimport { Link } from 'react-router';\r\nimport Paper from 'material-ui/Paper';\r\nimport sofaOneTilesData from '../../constants/goodsData.js';\r\nimport '../../../css/Animation.css';\r\n\r\nconst SofaPage = ({\r\n  imgSrc,\r\n  onShowItemPicture,\r\n  onChangeAllPreviewGoods,\r\n}) => (\r\n  <div>\r\n    <Link to={{ \r\n      pathname: '/goods',\r\n    }}>\r\n　　　<Paper zDepth={5} circle={true}> \r\n　　　　<img src=\"./img/sofa/size1.JPG\"\r\n　　　　　onMouseLeave={ ()=> onShowItemPicture(\"./img/sofa/sofa_main.JPG\") } \r\n　　　　　onMouseOver={ ()=> onShowItemPicture(\"./img/sofa/size1.JPG\") } \r\n　　　　　onClick={ ()=> onChangeAllPreviewGoods(sofaOneTilesData) }/>\r\n　　　</Paper>\r\n    </Link>\r\n    <Paper zDepth={5} circle={true}> \r\n　　　<img src={imgSrc? imgSrc:\"./img/home.PNG\"}/>\r\n　</Paper>\r\n  </div>\r\n);\r\n```\r\n\r\n```javascript\r\n//Components - GoodsPage.js\r\nimport React from 'react';\r\nimport { Link } from 'react-router';\r\nimport {GridList, GridTile} from 'material-ui/GridList';\r\nimport IconButton from 'material-ui/IconButton';\r\nimport StarBorder from 'material-ui/svg-icons/toggle/star-border';\r\nimport Immutable from 'immutable';\r\n\r\nconst GoodsPage = (props) => (\r\n  <div style={styles.root}>\r\n    <GridList\r\n      cols={2}\r\n      cellHeight={200}\r\n      padding={1}\r\n      style={styles.gridList}\r\n    >\r\n      {props.data.valueSeq().map((tile) => (\r\n        <GridTile\r\n          key={tile.img}\r\n          title={tile.title}\r\n          actionIcon={<IconButton><StarBorder color=\"white\"/></IconButton>}\r\n          actionPosition=\"left\"\r\n          titlePosition=\"top\"\r\n          titleBackground=\"linear-gradient(to bottom, rgba(0,0,0,0.7) 0%,rgba(0,0,0,0.3) 70%,rgba(0,0,0,0) 100%)\"\r\n          cols={tile.featured ? 2 : 1}\r\n          rows={tile.featured ? 2 : 1}\r\n        >\r\n          <img src={tile.img} />\r\n        </GridTile>\r\n      ))}\r\n    </GridList>\r\n  </div>\r\n);\r\n```"},"comment":{"url":"https://api.github.com/repos/reactjs/redux/issues/comments/251292610","html_url":"https://github.com/reactjs/redux/issues/2010#issuecomment-251292610","issue_url":"https://api.github.com/repos/reactjs/redux/issues/2010","id":251292610,"user":{"login":"Crygar","id":17195992,"avatar_url":"https://avatars.githubusercontent.com/u/17195992?v=3","gravatar_id":"","url":"https://api.github.com/users/Crygar","html_url":"https://github.com/Crygar","followers_url":"https://api.github.com/users/Crygar/followers","following_url":"https://api.github.com/users/Crygar/following{/other_user}","gists_url":"https://api.github.com/users/Crygar/gists{/gist_id}","starred_url":"https://api.github.com/users/Crygar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Crygar/subscriptions","organizations_url":"https://api.github.com/users/Crygar/orgs","repos_url":"https://api.github.com/users/Crygar/repos","events_url":"https://api.github.com/users/Crygar/events{/privacy}","received_events_url":"https://api.github.com/users/Crygar/received_events","type":"User","site_admin":false},"created_at":"2016-10-04T04:23:26Z","updated_at":"2016-10-04T04:23:26Z","body":"Oh, I can't believe I misuse {} as () in container. You save my day, thank you!!"}}
{"actor":{"display_login":"Crygar"}}