@@ -8,6 +8,7 @@ export interface Component {
88interface ComponentLookupProps {
99 componentType : string ;
1010 componentIndex : number ;
11+ propIndex ?: number ;
1112}
1213
1314export interface ComponentLookup {
@@ -44,7 +45,8 @@ class ReactFromJSON<
4445
4546 ComponentLookup = ( {
4647 componentIndex,
47- componentType
48+ componentType,
49+ propIndex
4850 } : ComponentLookupProps ) => {
4951 const { components } = this . props ;
5052
@@ -58,12 +60,13 @@ class ReactFromJSON<
5860 ...component ,
5961 props : {
6062 id : component . id || componentIndex , // Map id to component props if specified on root. Otherwise, use index.
63+ propIndex : propIndex ,
6164 ...component . props
6265 }
6366 } ) ;
6467 } ;
6568
66- resolveProp = ( prop : any ) : any => {
69+ resolveProp = ( prop : any , index ?: number ) : any => {
6770 if ( prop === null ) {
6871 return prop ;
6972 } else if ( Array . isArray ( prop ) ) {
@@ -76,23 +79,25 @@ class ReactFromJSON<
7679 ) {
7780 const component : Component = prop ;
7881
79- return this . renderComponent ( component ) ;
82+ return this . renderComponent ( component , index ) ;
8083 }
8184 }
8285
8386 return prop ;
8487 } ;
8588
86- getNextKey ( type : string ) {
89+ getNextKey ( type : string , propIndex ?: number ) {
8790 this . counter [ type ] = this . counter [ type ] || 0 ;
88- return `${ type } _${ this . counter [ type ] ++ } ` ;
91+ const propIndexKey =
92+ typeof propIndex !== "undefined" ? `_${ propIndex } ` : "" ;
93+ return `${ type } _${ this . counter [ type ] ++ } ${ propIndexKey } ` ;
8994 }
9095
91- renderComponent ( component : Component ) {
96+ renderComponent ( component : Component , propIndex ?: number ) {
9297 const { mapping } = this . props ;
9398 const { type, props } = component ;
9499 const resolvedProps = { } ;
95- const key = this . getNextKey ( type ) ;
100+ const key = this . getNextKey ( type , propIndex ) ;
96101
97102 const propKeys = Object . keys ( props ) ;
98103
@@ -109,7 +114,9 @@ class ReactFromJSON<
109114 throw `Tried to render the "${ type } " component, but it's not specified in your mapping.` ;
110115 }
111116
112- return < MappedComponent key = { key } { ...resolvedProps } /> ;
117+ return (
118+ < MappedComponent key = { key } propIndex = { propIndex } { ...resolvedProps } />
119+ ) ;
113120 }
114121
115122 render ( ) {
0 commit comments