Skip to content

Commit

Permalink
Add a note about ErrorBoundary to state persistence docs
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jun 24, 2024
1 parent 4ce5289 commit 17c6783
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion versioned_docs/version-6.x/state-persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export default function App() {
}
```

:::warning

It is recommended to use an [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) in your app and clear the persisted state if an error occurs. This will ensure that the app doesn't get stuck in an error state if a screen crashes.

:::

### Development Mode

This feature is particularly useful in development mode. You can enable it selectively using the following approach:
Expand All @@ -80,7 +86,7 @@ This feature is particularly useful in development mode. You can enable it selec
const [isReady, setIsReady] = React.useState(__DEV__ ? false : true);
```

While it can be used for production as well, use it with caution as it can make the app unusable if the app is crashing on a particular screen - as the user will still be on the same screen after restarting.
While it can be used for production as well, use it with caution as it can make the app unusable if the app is crashing on a particular screen - as the user will still be on the same screen after restarting. So if you are using it in production, make sure to clear the persisted state if an error occurs.

### Loading View

Expand Down
8 changes: 7 additions & 1 deletion versioned_docs/version-7.x/state-persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ export default function App() {
</TabItem>
</Tabs>

:::warning

It is recommended to use an [error boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) in your app and clear the persisted state if an error occurs. This will ensure that the app doesn't get stuck in an error state if a screen crashes.

:::

### Development Mode

This feature is particularly useful in development mode. You can enable it selectively using the following approach:
Expand All @@ -281,7 +287,7 @@ This feature is particularly useful in development mode. You can enable it selec
const [isReady, setIsReady] = React.useState(__DEV__ ? false : true);
```

While it can be used for production as well, use it with caution as it can make the app unusable if the app is crashing on a particular screen - as the user will still be on the same screen after restarting.
While it can be used for production as well, use it with caution as it can make the app unusable if the app is crashing on a particular screen - as the user will still be on the same screen after restarting. So if you are using it in production, make sure to clear the persisted state if an error occurs.

### Loading View

Expand Down

0 comments on commit 17c6783

Please sign in to comment.