Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronously initialize state required by child components #10770

Closed
guardrex opened this issue Feb 2, 2019 — with docs.microsoft.com · 3 comments · Fixed by #12881
Closed

Asynchronously initialize state required by child components #10770

guardrex opened this issue Feb 2, 2019 — with docs.microsoft.com · 3 comments · Fixed by #12881
Assignees
Labels
Blazor Pri1 High priority, do before Pri2 and Pri3

Comments

Copy link
Collaborator

guardrex commented Feb 2, 2019

From danroth27 at aspnet/Blazor.Docs#240 ...

You can use OnInitAsync to asynchronously initialize some state needed by child components (ex retrieve a JWT needed for HTTP requests), but it takes some work and coordination. We should document how to do this.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@dotnet-bot dotnet-bot added the Source - Docs.ms Docs Customer feedback via GitHub Issue label Feb 2, 2019
@guardrex guardrex added Razor Components and removed Source - Docs.ms Docs Customer feedback via GitHub Issue labels Feb 2, 2019
@guardrex guardrex added this to the Backlog milestone Feb 2, 2019
@guardrex guardrex added Pri1 High priority, do before Pri2 and Pri3 and removed DT labels Feb 2, 2019
@guardrex guardrex self-assigned this May 15, 2019
@guardrex guardrex added the PU label Jun 6, 2019
@guardrex guardrex removed their assignment Jun 6, 2019
@mkArtakMSFT mkArtakMSFT added the 3.0 label Jun 6, 2019
@danroth27
Copy link
Member

I think that the only thing that really needs to be documented here is to note that for all of the async component lifecycle events any async actions performed in those event may not have completed before the component is rendered. So you need to make sure your rendering logic accounts for that (ex values still being retrieved may still be null or not defined yet). Typically this means writing some if statements in your rendering logic to check if things haven't been initialized yet and then render some placeholder UI ("Loading..." or whatever). You can see an example of this in the FetchData component in our templates. After the task returned by an async lifecycle event completes the component will be rendered again with the updated state.

@guardrex
Copy link
Collaborator Author

guardrex commented Jun 8, 2019

Note to PU: I can write this based on the guidance ☝️. If you'd prefer to pass it to me, drop the PU label and assign it to me.

@danroth27
Copy link
Member

@guardrex it's all yours 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blazor Pri1 High priority, do before Pri2 and Pri3
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants