In my render of my ReactJS component, I have a lot of duplication. I would like to be able to remove that duplication.
Here's the trimmed down version of the component:
export default class PageBody extends React.Component {
constructor(props) {
super(props);
this.state = {
displayState: 0
};
}
render() {
const whichLayout = this.state.displayState;
let resultLayout = null;
switch(whichLayout) {
case 1:
resultLayout = <div><Toolbar /><br /><PortfolioBody /></div>
break;
default:
resultLayout = <div><Toolbar /><br /><DefaultBody /></div>
break;
}
return (resultLayout);
}
}
What I thought would be a good idea is to concatenate resultLayout, but that doesn't seem to work:
let resultLayout = <div><Toolbar /><br />;
switch(whichLayout) {
case 1:
resultLayout = resultLayout + <PortfolioBody />
break;
default:
resultLayout = resultLayout + <DefaultBody />
break;
}
resultLayout = </div>;
Thoughts?
Thank you Matt