0 votes
in ReactJS by
What is suspense component in ReactJs?

1 Answer

0 votes
by

If the module containing the dynamic import is not yet loaded by the time parent component renders, you must show some fallback content while you’re waiting for it to load using a loading indicator. This can be done using Suspense component.

For example, the below code uses suspense component,

const OtherComponent = React.lazy(() => import("./OtherComponent"));

function MyComponent() {
  return (
    <div>
      <Suspense fallback={<div>Loading...</div>}>
        <OtherComponent />
      </Suspense>
    </div>
  );
}

As mentioned in the above code, Suspense is wrapped above the lazy component.

Related questions

0 votes
asked Nov 3, 2023 in ReactJS by AdilsonLima
0 votes
asked Oct 28, 2023 in ReactJS by DavidAnderson
...