diff --git a/Forte.Web.React/Configuration/ReactConfiguration.cs b/Forte.Web.React/Configuration/ReactConfiguration.cs
index 9789015..e926592 100644
--- a/Forte.Web.React/Configuration/ReactConfiguration.cs
+++ b/Forte.Web.React/Configuration/ReactConfiguration.cs
@@ -26,6 +26,12 @@ public class ReactConfiguration
///
public string NameOfObjectToSaveProps { get; set; } = "__reactProps";
+ ///
+ /// Name of the object used to save global data object. Default value is "__globalData".
+ /// NameOfGlobalDataToSave is supported by method.
+ ///
+ public string NameOfGlobalDataToSave { get; set; } = "__globalData";
+
///
/// Indicates whether caching is used. Default value is "true".
///
diff --git a/Forte.Web.React/ForteWebReactExtensions.cs b/Forte.Web.React/ForteWebReactExtensions.cs
index 0ef8ce1..2d4b0b8 100644
--- a/Forte.Web.React/ForteWebReactExtensions.cs
+++ b/Forte.Web.React/ForteWebReactExtensions.cs
@@ -48,7 +48,8 @@ public static void AddReact(this IServiceCollection services,
}
public static void UseReact(this IApplicationBuilder app, IEnumerable scriptUrls, Version reactVersion,
- bool disableServerSideRendering = false, string? nameOfObjectToSaveProps = null, bool? useCache = null, bool? strictMode = null)
+ bool disableServerSideRendering = false, string? nameOfObjectToSaveProps = null,
+ string? nameOfGlobalDataToSave = null, bool? useCache = null, bool? strictMode = null)
{
var config = app.ApplicationServices.GetService();
@@ -61,6 +62,7 @@ public static void UseReact(this IApplicationBuilder app, IEnumerable sc
config.ScriptUrls = scriptUrls.ToList();
config.ReactVersion = reactVersion;
config.NameOfObjectToSaveProps = nameOfObjectToSaveProps ?? config.NameOfObjectToSaveProps;
+ config.NameOfGlobalDataToSave = nameOfGlobalDataToSave ?? config.NameOfGlobalDataToSave;
config.UseCache = useCache ?? true;
config.StrictMode = strictMode ?? false;
}
diff --git a/Forte.Web.React/HtmlHelperExtensions.cs b/Forte.Web.React/HtmlHelperExtensions.cs
index 3883fd4..c78bca7 100644
--- a/Forte.Web.React/HtmlHelperExtensions.cs
+++ b/Forte.Web.React/HtmlHelperExtensions.cs
@@ -17,26 +17,34 @@ namespace Forte.Web.React;
public static class HtmlHelperExtensions
{
#if NET48
- public static IHtmlString React(this HtmlHelper _, string componentName, T props)
+ public static IHtmlString React(this HtmlHelper _, string componentName, T props, object? globalData = null)
{
var reactService = DependencyResolver.Current.GetService();
- var renderedComponent = reactService.RenderToStringAsync(componentName, props).GetAwaiter().GetResult();
+ var renderedComponent = reactService.RenderToStringAsync(componentName, props, globalData: globalData)
+ .GetAwaiter().GetResult();
return new HtmlString(renderedComponent);
}
-
- public static IHtmlString React(this HtmlHelper _, TComponent component) where TComponent : IReactComponent
+
+ public static IHtmlString React(this HtmlHelper _, TComponent component, object? globalData = null)
+ where TComponent : IReactComponent
{
var reactService = DependencyResolver.Current.GetService();
- var renderedComponent = reactService.RenderToStringAsync(component.Path, null, component.RenderingMode).GetAwaiter().GetResult();
+ var renderedComponent = reactService
+ .RenderToStringAsync(component.Path, null, component.RenderingMode, globalData)
+ .GetAwaiter().GetResult();
return new HtmlString(renderedComponent);
}
-
- public static IHtmlString React(this HtmlHelper _, TComponent component) where TComponent : IReactComponent where TProps : IReactComponentProps
+
+ public static IHtmlString React(this HtmlHelper _, TComponent component,
+ object? globalData = null)
+ where TComponent : IReactComponent where TProps : IReactComponentProps
{
var reactService = DependencyResolver.Current.GetService();
- var renderedComponent = reactService.RenderToStringAsync(component.Path, component.Props, component.RenderingMode).GetAwaiter().GetResult();
+ var renderedComponent = reactService
+ .RenderToStringAsync(component.Path, component.Props, component.RenderingMode, globalData).GetAwaiter()
+ .GetResult();
return new HtmlString(renderedComponent);
}
@@ -47,28 +55,38 @@ public static IHtmlString InitJavascript(this HtmlHelper _)
return new HtmlString(reactService.GetInitJavascript());
}
+}
#endif
#if NET6_0_OR_GREATER
- public static async Task ReactAsync(this IHtmlHelper htmlHelper, string componentName, T props)
+ public static async Task ReactAsync(this IHtmlHelper htmlHelper, string componentName, T props,
+ object? globalData = null)
{
var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService();
- return new HtmlString(await reactService.RenderToStringAsync(componentName, props));
+ return new HtmlString(
+ await reactService.RenderToStringAsync(componentName, props, globalData: globalData));
}
-
- public static async Task ReactAsync(this IHtmlHelper htmlHelper, TComponent component) where TComponent : IReactComponent
+
+ public static async Task ReactAsync(this IHtmlHelper htmlHelper, TComponent component,
+ object? globalData = null)
+ where TComponent : IReactComponent
{
var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService();
- return new HtmlString(await reactService.RenderToStringAsync(component.Path, null, component.RenderingMode));
+ return new HtmlString(
+ await reactService.RenderToStringAsync(component.Path, null, component.RenderingMode, globalData));
}
-
- public static async Task ReactAsync(this IHtmlHelper htmlHelper, TComponent component) where TComponent : IReactComponent where TProps : IReactComponentProps
+
+ public static async Task ReactAsync(this IHtmlHelper htmlHelper,
+ TComponent component, object? globalData =
+ null) where TComponent : IReactComponent where TProps : IReactComponentProps
{
var reactService = htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService();
- return new HtmlString(await reactService.RenderToStringAsync(component.Path, component.Props, component.RenderingMode));
+ return new HtmlString(
+ await reactService.RenderToStringAsync(component.Path, component.Props, component.RenderingMode,
+ globalData));
}
public static IHtmlContent InitJavascript(this IHtmlHelper htmlHelper)
@@ -77,5 +95,5 @@ public static IHtmlContent InitJavascript(this IHtmlHelper htmlHelper)
return new HtmlString(reactService.GetInitJavascript());
}
-#endif
}
+#endif
diff --git a/Forte.Web.React/React/ReactService.cs b/Forte.Web.React/React/ReactService.cs
index d6a9c24..608a1fa 100644
--- a/Forte.Web.React/React/ReactService.cs
+++ b/Forte.Web.React/React/ReactService.cs
@@ -16,7 +16,9 @@ public interface IReactService
Task> GetAvailableComponentNames();
Task RenderAsync(TextWriter writer, string componentName, object? props = null, RenderOptions? options = null);
- Task RenderToStringAsync(string componentName, object? props = null, RenderingMode renderingMode = RenderingMode.ClientAndServer);
+
+ Task RenderToStringAsync(string componentName, object? props = null,
+ RenderingMode renderingMode = RenderingMode.ClientAndServer, object? globalData = null);
}
public class ReactService : IReactService
@@ -65,7 +67,7 @@ public ReactService(INodeJSService nodeJsService, IJsonSerializationService json
}
#endif
- private async Task InvokeRenderTo(Component component, object? props = null, params object[] args)
+ private async Task InvokeRenderTo(Component component, object? props = null, object? globalData = null, params object[] args)
{
var allArgs = new List