Uncaught TypeError: users.map is not a function
Uncaught TypeError: users.map is not a function
我在 material ui 中使用数据网格。
我想创建与 params 中的数据一样多的行。
示例:(3) [{…}, {…}, {…}]
← 来自 User.includes(:evaluations).where(user_evaluations: { evaluation_id: 6 }).order('users.updated_at DESC')
所以我想出了最好的解决方案是使用 map 方法。
但是我得到了以下错误..
Uncaught TypeError: users.map is not a function
代码:
useEffect(() => {
axios
.get(`${process.env.REACT_APP_ENDPOINT}/admin/users`, {
headers: {
"access-token": access_token!,
client: client!,
uid: uid!,
},
})
.then((response) => {
console.log(response.data.created_at);
console.log(response.data.data);
setUsers(response.data.data);
})
.catch(() => {
dispatch(setSessionTimeout(true));
dispatch(setLoggedIn(false));
navigate("/");
});
}, []);
const columns: GridColDef[] = [
{ field: "id", headerName: "ID", width: 70 },
];
const rows = users.map((row: any) => ({
id: row.id,
}));
...
<DataGrid
rows={users}
columns={columns}
checkboxSelection
className={classes.data_grid_styles}
pageSize={pageSize}
rowsPerPageOptions={[15, 30, 50]}
onPageSizeChange={(newPageSize) =>
setPageSize(newPageSize)
}/>
response.data.data
的内容是:
0: {id: 1392, email: 'yuuyake91922211111@yahoo.co.jp', image: null, name_sei: 'テストああ', name_mei: 'name', …} 1: {id: 1391, email: 'yuuyake91911111@yahoo.co.jp', image: null, name_sei: 'テスト', name_mei: 'name', …} 2: {id: 1387, email: 'yuuyake9191asss@yahoo.co.jp', image: null, name_sei: 'あ', name_mei: 'あ', …} length: 3 [[Prototype]]: Array(0)
代码错误是什么?
如果您知道更好的解决方案:
So I came up that best solution is using map method.
告诉我。
请帮帮我..
我修好了!!
之前:
const [users, setUsers] = React.useState(Object);
之后:
const [users, setUsers] = React.useState([]);
我在 material ui 中使用数据网格。
我想创建与 params 中的数据一样多的行。
示例:(3) [{…}, {…}, {…}]
← 来自 User.includes(:evaluations).where(user_evaluations: { evaluation_id: 6 }).order('users.updated_at DESC')
所以我想出了最好的解决方案是使用 map 方法。
但是我得到了以下错误..
Uncaught TypeError: users.map is not a function
代码:
useEffect(() => {
axios
.get(`${process.env.REACT_APP_ENDPOINT}/admin/users`, {
headers: {
"access-token": access_token!,
client: client!,
uid: uid!,
},
})
.then((response) => {
console.log(response.data.created_at);
console.log(response.data.data);
setUsers(response.data.data);
})
.catch(() => {
dispatch(setSessionTimeout(true));
dispatch(setLoggedIn(false));
navigate("/");
});
}, []);
const columns: GridColDef[] = [
{ field: "id", headerName: "ID", width: 70 },
];
const rows = users.map((row: any) => ({
id: row.id,
}));
...
<DataGrid
rows={users}
columns={columns}
checkboxSelection
className={classes.data_grid_styles}
pageSize={pageSize}
rowsPerPageOptions={[15, 30, 50]}
onPageSizeChange={(newPageSize) =>
setPageSize(newPageSize)
}/>
response.data.data
的内容是:
0: {id: 1392, email: 'yuuyake91922211111@yahoo.co.jp', image: null, name_sei: 'テストああ', name_mei: 'name', …} 1: {id: 1391, email: 'yuuyake91911111@yahoo.co.jp', image: null, name_sei: 'テスト', name_mei: 'name', …} 2: {id: 1387, email: 'yuuyake9191asss@yahoo.co.jp', image: null, name_sei: 'あ', name_mei: 'あ', …} length: 3 [[Prototype]]: Array(0)
代码错误是什么?
如果您知道更好的解决方案:
So I came up that best solution is using map method.
告诉我。 请帮帮我..
我修好了!!
之前:
const [users, setUsers] = React.useState(Object);
之后:
const [users, setUsers] = React.useState([]);