I have a feeling there is a better / non repeatable way of fetching data from props.
Currently I'm mapping elements to props to get data like so:
@connect((store) => {
return {
listAdProductsData: store.listAdProductsData.data,
adProductsData: store.adProductsData.data,
foxFooterData: store.foxFooterData.data
}
})
To fetch data associated to the property I'm having to write a "getData" function within my container to check if the data is undefined as an array of objects to then pass down as props to my components like so:
getFoxData(){
let data;
if (this.props.foxFooterData.data === undefined) {
data = [{}];
} else {
data = this.props.foxFooterData.data[0];
}
return data
}
With this approach, I will need to write this function a further three two times to fetch data from listAdProductData and adProductsData.
Action to get data:
componentWillMount() {
//Fetch Fox Footer Data
this.props.dispatch(fetchFoxFooterData());
}
Here is what my render function looks like including passing the data down as props:
render() {
this.getFoxData();
return (
<div className="ad-products-wrap container no-padding col-xs-12">
<Footer data={this.getFoxData()} />
This seems laborious and repeating - surely there has to be a better approach to something like this?
<Footer data={this.props.foxFooterData ? this.props.foxFooterData.data[0] : [{}]} />