Skip to content
New issue

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

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

Already on GitHub? # to your account

Suspense and error handle in web-components #15

Closed
Tracked by #1
aralroca opened this issue Dec 12, 2023 · 0 comments · Fixed by #16
Closed
Tracked by #1

Suspense and error handle in web-components #15

aralroca opened this issue Dec 12, 2023 · 0 comments · Fixed by #16
Assignees
Labels
enhancement New feature or request

Comments

@aralroca
Copy link
Collaborator

aralroca commented Dec 12, 2023

Suspense: Generate a suspense phase if your web-component is async and you want to show something while the promise is pending. It also should work during HTML streaming.

export default async function MyWebComponent({}, { state }) {
  const foo = await fetch(/* ... */).then((r) => r.text());

  return <div>{foo}</div>;
}

MyWebComponent.suspense = (props, webContext) => <div>loading...</div>;

Error: generate a error phase if your web-component throws an error and you want to show something without crash the rest of the page.

import { WebContext } from 'brisa';

export default function SomeWebComponent() {
   /* some code */
}

SomeWebComponent.error = ({ error }, webContext: WebContext) => {
  return <p>Oops! {error.message}</p>;
};
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant