hydrostack / hydro

Hydro brings stateful and reactive components to ASP.NET Core without writing JavaScript

Home Page:https://usehydro.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support dynamic component generation

kjeske opened this issue · comments

Make it possible to automatically produce a Hydro component when an event occurs.

Example:

public Task AddPost()
{
    var post = new Post();
    database.Add(post);
    await database.SaveChanges();

    DispatchGlobal(new PostCreated(PostId: post.Id));
}
public class Post : HydroComponent
{
    public Guid PostId { get; set; }
}
<hydro name="Post" generate-on="typeof(PostCreated)" />

When AddPost action is triggered, it dispatches PostCreated event, which causes a new instance of Post component to render (thanks to generate-on) with the properties taken from the event (PostId).