react-admin useGetManyReference
// syntax
const { data, ids, total, loading, loaded, error, refetch } = useGetManyReference(resource, target, id, pagination, sort, filter, referencingResource, options);
// example
import { useGetManyReference } from 'react-admin';
const PostComments = ({ post_id }) => {
const { data, ids, loading, error } = useGetManyReference(
'comments',
'post_id',
post_id,
{ page: 1, perPage: 10 },
{ field: 'published_at', order: 'DESC' },
{},
'posts',
);
if (loading) { return <Loading />; }
if (error) { return <p>ERROR</p>; }
return (
<ul>
{ids.map(id =>
<li key={id}>{data[id].body}</li>
)}
</ul>
);
};