Skip to content

Commit 11a48f4

Browse files
committed
Cleanup readme
1 parent e6fe00d commit 11a48f4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ const OtherComponent = lazy(() => import("./OtherComponent"));
2626
OtherComponent.preload();
2727
```
2828

29+
To preload a component before it is rendered for the first time, the component that is returned from `lazy()` has a `preload` function attached that you can invoke. `preload()` returns a `Promise` that you can wait on if needed. The promise is idempotent, meaning that `preload()` will return the same `Promise` instance if called multiple times.
30+
2931
For more information about React code-splitting, `React.lazy` and `React.Suspense`, see https://reactjs.org/docs/code-splitting.html.
3032

3133
## Example
3234

33-
To preload a component before it is rendered for the first time, the component that is returned from `lazy()` has a `preload` function attached that you can invoke.
34-
3535
For example, if you need to load a component when a button is pressed, you could start preloading the component when the user hovers over the button:
3636

3737
```js
3838
function SomeComponent() {
39-
const { showOtherComponent, setshowOtherComponent } = useState(false);
39+
const { showOtherComponent, setShowOtherComponent } = useState(false);
4040

4141
return (
4242
<div>
4343
<Suspense fallback={<div>Loading...</div>}>
4444
{showOtherComponent && <OtherComponent />}
4545
</Suspense>
4646
<button
47-
onClick={() => setshowOtherComponent(true)}
47+
onClick={() => setShowOtherComponent(true)}
4848
// This component will be needed soon. Let's preload it!
4949
onMouseOver={() => OtherComponent.preload()}
5050
>

0 commit comments

Comments
 (0)