diff --git a/src/index.es6 b/src/index.es6 index 6148848..11f0ed8 100644 --- a/src/index.es6 +++ b/src/index.es6 @@ -61,7 +61,9 @@ function buildChildren( tokens, components ) { break; } // componentSelfClosing token - children.push( components[ token.value ] ); + if ( components[ token.value ] ) { + children.push( React.cloneElement( components[ token.value ], { key: i } ) ); + } continue; } @@ -69,7 +71,7 @@ function buildChildren( tokens, components ) { closeIndex = getCloseIndex( openIndex, tokens ); grandChildTokens = tokens.slice( ( openIndex + 1 ), closeIndex ); grandChildren = buildChildren( grandChildTokens, components ); - clonedOpenComponent = React.cloneElement( openComponent, {}, grandChildren ); + clonedOpenComponent = React.cloneElement( openComponent, { key: openIndex }, grandChildren ); children.push( clonedOpenComponent ); if ( closeIndex < tokens.length - 1 ) { @@ -83,17 +85,7 @@ function buildChildren( tokens, components ) { return children[ 0 ]; } - return children.map( ( child, index ) => { - if ( child ) { - return React.cloneElement( - child, - { key: `interpolation-child-${ index }` }, - child.props !== undefined - ? child.props.children - : undefined - ); - } - } ); + return children; } function interpolate( options ) {