【问题标题】:React-Admin - How to create a list view with autorefreshReact-Admin - 如何使用自动刷新创建列表视图
【发布时间】:2020-07-03 15:37:35
【问题描述】:

我正在尝试创建一个列表视图,例如每 15 秒自动重新加载一次。 是否可以在 react admin 框架中创建具有自动刷新功能的列表视图?

【问题讨论】:

标签: react-admin


【解决方案1】:

我终于想到了下一个解决方案:

const useAutoRefresh = function(url, interval){ 
    
    const refresh = useRefresh();

    useEffect(() => {           

        const timerAction = function(){         

            if(!document.hidden &&
              window.location.href.toLowerCase().endsWith(url.toLowerCase())){              
                refresh();
            }
        }

        setInterval(timerAction, interval); 
      }, []);   
}

现在我们可以在 ListView 中使用这个函数

export const ProductCardList = (props) => (
    <List {...props} {...useAutoRefresh('/productcard', 5000)}>     

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    • 2018-07-27
    • 2020-07-13
    • 1970-01-01
    • 2014-12-14
    相关资源
    最近更新 更多