diff --git a/common/components/ProductsContainer.jsx b/common/components/ProductsContainer.jsx index 1881f2d..375f025 100755 --- a/common/components/ProductsContainer.jsx +++ b/common/components/ProductsContainer.jsx @@ -24,6 +24,9 @@ class ProductsContainer extends Component { } componentDidMount() { + if (this.props.products.get('$fetched')) { + return + } fetchNeeds( ProductsContainer.needs, this.props ) } diff --git a/common/constants/Types.js b/common/constants/Types.js index 521baaf..ae641b5 100644 --- a/common/constants/Types.js +++ b/common/constants/Types.js @@ -3,6 +3,7 @@ import Immutable from 'immutable'; // define ProductState shape inside redux state export const ProductState = Immutable.Record({ + $fetched: false, productsById: Immutable.Map(), total: '0', }) diff --git a/common/utils/fetchComponentData.js b/common/utils/fetchComponentData.js index 46fcd54..7746cf3 100644 --- a/common/utils/fetchComponentData.js +++ b/common/utils/fetchComponentData.js @@ -4,7 +4,10 @@ export default function fetchComponentData(dispatch, components, params) { const needs = components.reduce( (prev, current) => { return Object.keys(current).reduce( (acc, key) => { - return current[key].hasOwnProperty('needs') ? current[key].needs.concat(acc) : acc + if (!!current[key] && current[key].hasOwnProperty('needs')) { + return current[key].needs.concat(acc) + } + return acc }, prev) }, []);