'react admin useGetList with List component request api two times or how to prevent request api if already get data from useGetList
I use react admin with rest api and everything is fine till i need to manipulate data, so i decided to use useGetList from react admin and pass data through List
and it cause two times request my api:
useGetListand it is correctListalso trigger request - i need to prevent it (need to use List due to pagination UI), and do not understand how it can be prevented if i already have data fromuseGetList
Resource:
<Resource
name='allmyusers'
list={LatestNews}
/>
LatestNews component:
import {useState} from 'react'
import { useGetList, Loading, List } from 'react-admin';
const MyComponent =() =>{
const [page, setPage] = useState(1);
let { data, total, isLoading, error } = useGetList(
'allmyusers',
{
pagination: { page: page, perPage: 7 },
sort: { field: 'id', order: 'DESC' }
}
);
if (isLoading) { return <Loading />; }
if (error) { return <p>ERROR</p>; }
if (data){
data[0].title = 'testChangeData'
}
return(
<>
<List props={data}
>
<h1>Latest news</h1>
<ul>
{data.map(record =>
<li key={record.id}>{record.title}</li>
)}
</ul>
<p>{data.length} / {total} articles</p>
</List>
</>
)
}
const LatestNews = () => {
return (
< MyComponent
/>
);
};
export default LatestNews
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
