有没有办法从 material-table 中的自定义操作手动触发 isLoading 动画?
Is there a way to manually fire the isLoading animation from a custom action in material-table?
我正在使用 material-table 库。我想使用库用于自定义异步操作的当前加载动画。单击自定义操作后,它会打开,然后在 ync 解析后关闭。
import React from "react";
import MaterialTable from "material-table";
import ReactDOM from "react-dom";
import "./styles.css";
const handleAsync = () => {
// isLoading = true
// async done
// isLoading = false
}
function App() {
return (
<MaterialTable
columns={[
{
title: <button onClick={handleAsync}>async</button>
},
{
title: "Avatar",
field: "avatar",
render: rowData => (
<img
style={{ height: 36, borderRadius: "50%" }}
src={rowData.avatar}
/>
)
},
{ title: "Id", field: "id" },
{ title: "First Name", field: "first_name" },
{ title: "Last Name", field: "last_name" }
]}
data={query =>
new Promise((resolve, reject) => {
let url = "https://reqres.in/api/users?";
url += "per_page=" + query.pageSize;
url += "&page=" + (query.page + 1);
fetch(url)
.then(response => response.json())
.then(result => {
resolve({
data: result.data,
page: result.page - 1,
totalCount: result.total
});
});
})
}
title="Remote Data Example"
/>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
您可以使用 isLoading
material-table 的道具。就像这样:
<MaterialTable
...//
isLoading={this.state.isLoading}
/>
在异步操作之前设置 state.isLoading=true
,然后在操作完成后设置 false
我正在使用 material-table 库。我想使用库用于自定义异步操作的当前加载动画。单击自定义操作后,它会打开,然后在 ync 解析后关闭。
import React from "react";
import MaterialTable from "material-table";
import ReactDOM from "react-dom";
import "./styles.css";
const handleAsync = () => {
// isLoading = true
// async done
// isLoading = false
}
function App() {
return (
<MaterialTable
columns={[
{
title: <button onClick={handleAsync}>async</button>
},
{
title: "Avatar",
field: "avatar",
render: rowData => (
<img
style={{ height: 36, borderRadius: "50%" }}
src={rowData.avatar}
/>
)
},
{ title: "Id", field: "id" },
{ title: "First Name", field: "first_name" },
{ title: "Last Name", field: "last_name" }
]}
data={query =>
new Promise((resolve, reject) => {
let url = "https://reqres.in/api/users?";
url += "per_page=" + query.pageSize;
url += "&page=" + (query.page + 1);
fetch(url)
.then(response => response.json())
.then(result => {
resolve({
data: result.data,
page: result.page - 1,
totalCount: result.total
});
});
})
}
title="Remote Data Example"
/>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
您可以使用 isLoading
material-table 的道具。就像这样:
<MaterialTable
...//
isLoading={this.state.isLoading}
/>
在异步操作之前设置 state.isLoading=true
,然后在操作完成后设置 false