按钮刷新AppBar
不是在页面仪表板上刷新,因为我只使用组件Card
但使用组件List
或在页面上工作Datagrid
,所以我想配置显示/隐藏刷新按钮AppBar
或如何修复它对页面不使用组件List
或Datagrid
.
对不起,我英语不强。
您必须从 react-admin 状态获取一些数据才能使其工作。实际上,刷新按钮只是触发refreshView
更新state.admin.ui.viewVersion
react-admin redux 状态的键的操作。这个键是一个简单的计数器。在内部,我们使用这个计数器来检查我们是否必须更新某些组件数据。这是一个连接的简单示例,Dashboard
它可以在刷新时执行操作:
import React, { Component } from "react";
import { connect } from "react-redux";
class Dashboard extends Component {
componentDidMount() {
this.doOnMountAndWhenRefreshed();
}
componentDidUpdate(prevProps) {
if (prevProps.views !== this.props.views) {
this.doOnMountAndWhenRefreshed();
}
}
doOnMountAndWhenRefreshed = () => {
// This is where you do update your component:
// - Make API requests
// - Fetch data from the react-admin store, etc.
};
render() {
const { views } = this.props;
return <div>Refreshed {views} times.</div>;
}
}
const mapStateToProps = state => ({ views: state.admin.ui.viewVersion });
export default connect(
mapStateToProps,
{}
)(Dashboard);
你可以看到它在这个代码和框中工作
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句