Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions public/Feliz/React/SubscriptionsWithEffects.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,9 @@ let Main() =
]
]
```

When `renderChild` is set to `false`, the statement `if renderChild then UseToken(setFailed)` causes the `UseToken` component to be unmounted. During this process, the cancellation token created by `React.useCancellationToken()` inside `UseToken` is automatically disposed.

Since the async operation was started with `Async.StartImmediate(a,token.current)`, the disposal of the token cancels the ongoing asynchronous task. This prevents the async code from continuing to execute and potentially causing errors or unexpected behavior after the component is no longer displayed.

This pattern ensures that asynchronous operations are properly cleaned up when components are unmounted, which is crucial for preventing memory leaks and maintaining the expected behavior of your React application.