import React from 'react';
import {FirstCustomComponent} from './somewhere';
import {SecondCustomComponent} from './somewhere-else';
const ThirdCustomComponent = ({componentTitle, apple, banana}) => (
 componentTitle === 'FirstCustomComponent' 
    ? <FirstCustomComponent apple={apple} banana={banana} />
    : <SecondCustomComponent apple={apple} banana={banana} />
);
export default ThirdCustomComponent;
What is a good way to avoid the repetition in the code sample above? I've tried dynamically generating a component by setting const DynamicComponent = props.componentTitle and then returning <DynamicComponent apple={props.apple} banana={props.banana} /> but no luck.