@@ -38,14 +38,19 @@ public class ReactComponent : IReactComponent
3838 private readonly IReactSiteConfiguration _configuration ;
3939
4040 /// <summary>
41- /// Name of the component
41+ /// Gets or sets the name of the component
4242 /// </summary>
43- private readonly string _componentName ;
43+ public string ComponentName { get ; set ; }
4444
4545 /// <summary>
46- /// Unique ID for the DIV container of this component
46+ /// Gets or sets the unique ID for the DIV container of this component
4747 /// </summary>
48- private readonly string _containerId ;
48+ public string ContainerId { get ; set ; }
49+
50+ /// <summary>
51+ /// Gets or sets the HTML tag the component is wrapped in
52+ /// </summary>
53+ public string ContainerTag { get ; set ; }
4954
5055 /// <summary>
5156 /// Gets or sets the props for this component
@@ -64,8 +69,9 @@ public ReactComponent(IReactEnvironment environment, IReactSiteConfiguration con
6469 EnsureComponentNameValid ( componentName ) ;
6570 _environment = environment ;
6671 _configuration = configuration ;
67- _componentName = componentName ;
68- _containerId = containerId ;
72+ ComponentName = componentName ;
73+ ContainerId = containerId ;
74+ ContainerTag = "div" ;
6975 }
7076
7177 /// <summary>
@@ -81,20 +87,20 @@ public string RenderHtml()
8187 var html = _environment . Execute < string > (
8288 string . Format ( "React.renderToString({0})" , GetComponentInitialiser ( ) )
8389 ) ;
84- // TODO: Allow changing of the wrapper tag element from a DIV to something else
8590 return string . Format (
86- "<div id=\" {0}\" >{1}</div>" ,
87- _containerId ,
88- html
89- ) ;
91+ "<{2} id=\" {0}\" >{1}</{2}>" ,
92+ ContainerId ,
93+ html ,
94+ ContainerTag
95+ ) ;
9096 }
9197 catch ( JsRuntimeException ex )
9298 {
9399 throw new ReactServerRenderingException ( string . Format (
94100 "Error while rendering \" {0}\" to \" {2}\" : {1}" ,
95- _componentName ,
101+ ComponentName ,
96102 ex . Message ,
97- _containerId
103+ ContainerId
98104 ) ) ;
99105 }
100106 }
@@ -110,7 +116,7 @@ public string RenderJavaScript()
110116 return string . Format (
111117 "React.render({0}, document.getElementById({1}))" ,
112118 GetComponentInitialiser ( ) ,
113- JsonConvert . SerializeObject ( _containerId , _configuration . JsonSerializerSettings ) // SerializeObject accepts null settings
119+ JsonConvert . SerializeObject ( ContainerId , _configuration . JsonSerializerSettings ) // SerializeObject accepts null settings
114120 ) ;
115121 }
116122
@@ -122,14 +128,14 @@ private void EnsureComponentExists()
122128 // This is safe as componentName was validated via EnsureComponentNameValid()
123129 var componentExists = _environment . Execute < bool > ( string . Format (
124130 "typeof {0} !== 'undefined'" ,
125- _componentName
131+ ComponentName
126132 ) ) ;
127133 if ( ! componentExists )
128134 {
129135 throw new ReactInvalidComponentException ( string . Format (
130136 "Could not find a component named '{0}'. Did you forget to add it to " +
131137 "App_Start\\ ReactConfig.cs?" ,
132- _componentName
138+ ComponentName
133139 ) ) ;
134140 }
135141 }
@@ -143,7 +149,7 @@ private string GetComponentInitialiser()
143149 var encodedProps = JsonConvert . SerializeObject ( Props , _configuration . JsonSerializerSettings ) ; // SerializeObject accepts null settings
144150 return string . Format (
145151 "{0}({1})" ,
146- _componentName ,
152+ ComponentName ,
147153 encodedProps
148154 ) ;
149155 }
0 commit comments