You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Defer loading a component's code until it is rendered for the first time.
10
+
///
11
+
/// The `lazy` function is used to create lazy components in react-dart. Lazy components are able to run asynchronous code only when they are trying to be rendered for the first time, allowing for deferred loading of the component's code.
12
+
///
13
+
/// To use the `lazy` function, you need to wrap the lazy component with a `Suspense` component. The `Suspense` component allows you to specify what should be displayed while the lazy component is loading, such as a loading spinner or a placeholder.
14
+
///
15
+
/// Example usage:
16
+
/// ```dart
17
+
/// import 'package:react/react.dart' show lazy, Suspense;
18
+
/// import './simple_component.dart' deferred as simple;
19
+
///
20
+
/// final lazyComponent = lazy(() async {
21
+
/// await simple.loadLibrary();
22
+
/// return simple.SimpleComponent;
23
+
/// });
24
+
///
25
+
/// // Wrap the lazy component with Suspense
26
+
/// final app = Suspense(
27
+
/// {
28
+
/// fallback: 'Loading...',
29
+
/// },
30
+
/// lazyComponent({}),
31
+
/// );
32
+
/// ```
33
+
///
34
+
/// Defer loading a component’s code until it is rendered for the first time.
35
+
///
36
+
/// Lazy components need to be wrapped with `Suspense` to render.
37
+
/// `Suspense` also allows you to specify what should be displayed while the lazy component is loading.
0 commit comments