So react-admin seems to have a feature where if you’re idle for a little while and come back it will reload the data, presumably to make sure you’re looking at the most up to date version of a record.
This is causing some issues for my editing feature that has some custom components. Is there a way to disable this auto-reload feature?
Advertisement
Answer
The auto-refresh is triggered by the loading indicator (the spinner icon that you see in the top right part of the app bar).
You can disable the auto-refresh by replacing the loading indicator by your own.
JavaScript
x
44
44
1
import * as React from 'react';
2
import PropTypes from 'prop-types';
3
import classNames from 'classnames';
4
import { useSelector } from 'react-redux';
5
import { makeStyles } from '@material-ui/core/styles';
6
import CircularProgress from '@material-ui/core/CircularProgress';
7
import { useRefreshWhenVisible, RefreshIconButton } from 'react-admin';
8
9
const useStyles = makeStyles(
10
{
11
loader: {
12
margin: 14,
13
},
14
loadedIcon: {},
15
},
16
{ name: 'RaLoadingIndicator' }
17
);
18
19
const LoadingIndicator = props => {
20
const { classes: classesOverride, className, rest } = props;
21
useRefreshWhenVisible(); // <= comment this line to disable auto-refresh
22
const loading = useSelector(state => state.admin.loading > 0);
23
const classes = useStyles(props);
24
return loading ? (
25
<CircularProgress
26
className={classNames('app-loader', classes.loader, className)}
27
color="inherit"
28
size={18}
29
thickness={5}
30
{rest}
31
/>
32
) : (
33
<RefreshIconButton className={classes.loadedIcon} />
34
);
35
};
36
37
LoadingIndicator.propTypes = {
38
classes: PropTypes.object,
39
className: PropTypes.string,
40
width: PropTypes.string,
41
};
42
43
export default LoadingIndicator;
44
You’ll also need to put this button in a custom AppBar, inject your AppBar in a custom Layout, and use that Layout in your Admin, as explained in the react-admin Theming documentation.