@@ -233,38 +233,33 @@ Note that if you use this ability to pass a React node, the message will not be
233233If you have custom actions in your notification element, you can leverage the ` useCloseNotification ` hook to close the notification programmatically:
234234
235235``` tsx
236- import { useFormContext } from ' react-hook-form' ;
237- import { Button , useCloseNotification , useNotify } from ' react-admin' ;
238- import { SnackbarContent } from ' @mui/material' ;
236+ import { useCheckForApplicationUpdate , useCloseNotification , useNotify } from ' react-admin' ;
237+ import { Button , SnackbarContent } from ' @mui/material' ;
239238
240- const SetFormValueButton = () => {
241- const { setValue } = useFormContext ();
239+ export const CheckForApplicationUpdate = () => {
242240 const notify = useNotify ();
243241
244- return (
245- <Button
246- onClick = { () => {
247- setValue (' myfield' , ' a value' );
248- notify (<SetFormValueNotification reset = { () => setValue (' myfield' , ' ' )} />);
249- }}
250- label = " Set myfield value"
251- />
252- );
242+ const onNewVersionAvailable = () => {
243+ // autoHideDuration is set to 0 to disable the auto hide feature
244+ notify (<ApplicationUpdateNotification />, { autoHideDuration: 0 });
245+ };
246+
247+ useCheckForApplicationUpdate ({ onNewVersionAvailable , ... rest });
248+ return null ;
253249};
254250
255- const SetFormValueNotification = ({ reset }: { reset: () => void }) => {
251+ const ApplicationUpdateNotification = ({ reset }: { reset: () => void }) => {
256252 const closeNotification = useCloseNotification ();
257253
258254 return (
259255 <SnackbarContent
260- message = " myfield changed "
256+ message = " A new application version is available. Refresh your browser tab to update "
261257 action = {
262258 <Button
263259 onClick = { () => {
264- reset ();
265260 closeNotification ();
266261 }}
267- label = " Reset "
262+ label = " Dismiss "
268263 />
269264 }
270265 />
0 commit comments