Skip to content

Best way to run JavaScript on the server before some components #142

@SoonDead

Description

@SoonDead

I have a scenario where I have a few independent components on a page accessing data from a "central store". The central store needs to be initialized before the components first render.

My first solution was (before introducing server side rendering), to simply call store.initialize() before React.render()

Now I would need to somehow call store.initialize() on the server before calling @Html.React() in the same JS context.

I could call ReactSiteConfiguration.Configuration.AddScript() on a file that initializes the store, but that runs on every page of my application.

I want to initialize the store on specific pages only.

I would somehow need to get the JavaScript engine instance that React.NET uses from JsEngineSwitcher and call Execute("store.initialize();") on it.

Can I do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions