当前位置 : 主页 > 手机开发 > harmonyos >

前端项目实战贰佰伍拾伍react-admin+material ui-react-admin-admin中useGetList

来源:互联网 收集:自由互联 发布时间:2023-08-26
import { useGetList } from 'react-admin';const LatestNews = () = { const { data, total, isLoading, error } = useGetList( 'posts', { pagination: { page: 1, perPage: 10 }, sort: { field: 'published_at', order: 'DESC' } } ); if (isLoading) { r


import { useGetList } from 'react-admin';

const LatestNews = () => {
    const { data, total, isLoading, error } = useGetList(
        'posts',
        { 
            pagination: { page: 1, perPage: 10 },
            sort: { field: 'published_at', order: 'DESC' }
        }
    );
    if (isLoading) { return <Loading />; }
    if (error) { return <p>ERROR</p>; }
    return (
        <>
            <h1>Latest news</h1>
            <ul>
                {data.map(record =>
                    <li key={record.id}>{record.title}</li>
                )}
            </ul>
            <p>{data.length} / {total} articles</p>
        </>
    );
};
网友评论