title: Assign a React component to a variable with extra props
body: <p>I'm working on a component mapping function that loops through a list of objects which have a <code>type</code> key. The function returns an object of types of React components, it looks like this:</p>
  
  <pre><code>import _ from 'lodash';
  import cellBodyTypes from './cellBodyTypes';
  import {
      GenericCellBody,
      SubData
  } from './components/CellBody';
  
  const columnMapper = {};
  
  _.forEach(cellBodyTypes, (type) =&gt; {
      switch (type) {
          case cellBodyTypes.SUB_DATA:
              columnMapper[type] = SubData;
              break;
          case cellBodyTypes.DEFAULT:
              columnMapper[type] = GenericCellBody;
              break;
          default:
              columnMapper[type] = GenericCellBody;
      }
  });
  
  export default columnMapper;
  </code></pre>
  
  <p>And it's used like this:</p>
  
  <pre><code>renderCellBody = (columnType, cellData, index) =&gt; {
      const type = columnType || cellBodyTypes.DEFAULT;
      const CellBodyComponent = columnMapper[type];
  
      return &lt;CellBodyComponent /&gt;;
  }
  </code></pre>
  
  <p>And the render looks something like:</p>
  
  <pre><code>render (
      &lt;div&gt;
          {this.props.cellData.map((cell, index) =&gt; (
              &lt;div key={cell.id}&gt;
                  {this.renderCellBody(cell.type, cell, index)}
              &lt;/div&gt;
          ))}
      &lt;/div&gt;
  );
  </code></pre>
  
  <p>What I want to do is to be able to assign column types for new cases which utilize the same React components as other cases, but decorate those new column types with additional props. Something like:</p>
  
  <pre><code>case cellBodyTypes.NUMBER_SUB_DATA:
      columnMapper[type] = React.cloneElement(SubData, {someAdditionalProp: 'something'});
      break;
  case cellBodyTypes.SINGLE_NUMBER:
      columnMapper[type] = React.cloneElement(GenericCellBody, {someAdditionalProp: 'something'});
      break;
  </code></pre>
  
  <p>I tried returning a clone of the React component using <code>React.cloneElement</code> but that does not work, as it gives me this error: <code>React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.</code></p>
  
  <p>Is there a way to do this? Am I close to the right path and just missing something? Thanks.</p>