What is a more succinct way of writing this. The pageType is always the same as the React element name and I should be able to do away with the switch statement.
import React, {Component, PropTypes} from 'react';
import Standard from './Standard/Standard';
import Banners from './Banners/Banners';
export default class ProductPages extends Component {
static propTypes = {
pageType: PropTypes.string.isRequired
}
render() {
let ProductPage;
switch (this.props.pageType) {
case 'Standard':
ProductPage = <Standard products={products}/>;
break;
case 'Banners':
ProductPage = <Banners products={products}/>;
break;
default:
throw new Error('pageType is not valid');
}
return ProductPage;
}
}
StandardandBannersare React components not just simpleElementsyou need do something like this jsfiddle.net/69z2wepo/26495React.createElement- jsfiddle.net/69z2wepo/26496