Skip to content

Commit 9d42d92

Browse files
authored
Merge pull request #9437 from smeng9/fix-app-update-doc
Add documentation for useCheckForApplicationUpdate
2 parents 72a452c + 62643f2 commit 9d42d92

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

docs/CheckForApplicationUpdate.md

+43-7
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ export const App = () => (
4141

4242
`<CheckForApplicationUpdate>` accepts the following props:
4343

44-
| Prop | Required | Type | Default | Description |
45-
| --------------- | -------- | -------- | ------------------ |-------------------------------------------------------------------- |
46-
| `interval` | Optional | number | `3600000` (1 hour) | The interval in milliseconds between two checks |
47-
| `disabled` | Optional | boolean | `false` in `production` mode | Whether the automatic check is disabled |
48-
| `notification` | Optional | ReactElement | | The notification to display to the user when an update is available |
49-
| `url` | Optional | string | current URL | The URL to download to check for code update |
44+
| Prop | Required | Type | Default | Description |
45+
| --------------- | -------- | -------------- | ------------------ |-------------------------------------------------------------------- |
46+
| `interval` | Optional | `number` | `3600000` (1 hour) | The interval in milliseconds between two checks |
47+
| `disabled` | Optional | `boolean` | `false` | Whether the automatic check is disabled |
48+
| `notification` | Optional | `ReactElement` | | The notification to display to the user when an update is available |
49+
| `onNewVersion Available` | Optional | `function` | | The effect to execute when a new version is detected. |
50+
| `url` | Optional | `string` | Current URL | The URL to download to check for code update |
5051

5152
## `interval`
5253

@@ -118,7 +119,42 @@ const MyLayout = ({ children, ...props }) => (
118119
);
119120
```
120121

121-
If you just want to customize the notification texts, including the button, check out the [Internationalization section](#internationalization).
122+
If you want to customize the behavior when a new version is available, checkout the [`onNewVersionAvailable` section](#onnewversionavailable). If you just want to customize the notification texts, including the button, check out the [Internationalization section](#internationalization).
123+
124+
## `onNewVersionAvailable`
125+
126+
Advanced users who wish to customize the handling function other than just displaying a notification can leverage the `onNewVersionAvailable` prop:
127+
128+
```tsx
129+
import { CheckForApplicationUpdate, useNotify } from "react-admin";
130+
131+
export const MyCheckForApplicationUpdate = () => {
132+
const notify = useNotify();
133+
134+
const onNewVersionAvailable = () => {
135+
// Perform a backup of user preference in localStorage in case bad things happen
136+
const preference1 = localStorage.getItem("preference1");
137+
const preference2 = localStorage.getItem("preference2");
138+
const checkpointData = {
139+
preference1,
140+
preference2,
141+
};
142+
localStorage.setItem(
143+
`checkpoint_${new Date().toISOString()}`,
144+
JSON.stringify(checkpointData),
145+
);
146+
147+
// Notify user
148+
notify("New Version Ready to Update");
149+
};
150+
151+
return (
152+
<CheckForApplicationUpdate
153+
onNewVersionAvailable={onNewVersionAvailable}
154+
/>
155+
);
156+
};
157+
```
122158

123159
## `url`
124160

0 commit comments

Comments
 (0)