ProductiveRage / Bridge.React

Bindings for Bridge.NET for React - write React applications in C#!
MIT License
74 stars 14 forks source link

An async version of GetInitialState()? #7

Closed Zaid-Ajaj closed 8 years ago

Zaid-Ajaj commented 8 years ago

Is there a way to do the following:

protected override async Task<State> GetInitialStateAsync() 
{
    return new State 
    {
        Data = await Server.DataAsync()
    };
}
ProductiveRage commented 8 years ago

I don't think so - and I don't think that it would make sense.. the "initial state" determines how to draw the component immediately, which is information that won't be available if there is an async operation that needs to be processed.

For cases like this, I tend to have a "no-data-yet" state - you might leave the Data property as null and display a "Loading.." symbol in that case. When the data becomes available, then you would call SetState and set a new value for Data, at which point you can render the component properly - with a "no results" message if there is no Data* or with the information that the Data reference contains.