-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
Comments
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. |
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. |
@guardrex it's all yours 😃 |
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.
The text was updated successfully, but these errors were encountered: