88import type { ReactElement , ReactNode , ElementType } from 'react' ;
99import Card from '@mui/material/Card' ;
1010import clsx from 'clsx' ;
11- import { useListContext , type RaRecord } from 'ra-core' ;
11+ import { ListControllerResult , useListContext , type RaRecord } from 'ra-core' ;
1212
1313import { Title } from '../layout/Title' ;
1414import { ListToolbar } from './ListToolbar' ;
@@ -36,8 +36,10 @@ export const ListView = <RecordType extends RaRecord = any>(
3636 component : Content = DefaultComponent ,
3737 title,
3838 empty = defaultEmpty ,
39+ render,
3940 ...rest
4041 } = props ;
42+ const listContext = useListContext < RecordType > ( ) ;
4143 const {
4244 defaultTitle,
4345 data,
@@ -48,9 +50,9 @@ export const ListView = <RecordType extends RaRecord = any>(
4850 total,
4951 hasNextPage,
5052 hasPreviousPage,
51- } = useListContext < RecordType > ( ) ;
53+ } = listContext ;
5254
53- if ( ! children || ( ! data && isPending && emptyWhileLoading ) ) {
55+ if ( ( ! children && ! render ) || ( ! data && isPending && emptyWhileLoading ) ) {
5456 return null ;
5557 }
5658
@@ -63,7 +65,9 @@ export const ListView = <RecordType extends RaRecord = any>(
6365 actions = { actions }
6466 />
6567 ) }
66- < Content className = { ListClasses . content } > { children } </ Content >
68+ < Content className = { ListClasses . content } >
69+ { render ? render ( listContext ) : children }
70+ </ Content >
6771 { ! error && pagination !== false && pagination }
6872 </ div >
6973 ) ;
@@ -102,7 +106,7 @@ export const ListView = <RecordType extends RaRecord = any>(
102106 ) ;
103107} ;
104108
105- export interface ListViewProps {
109+ export interface ListViewProps < RecordType extends RaRecord = any > {
106110 /**
107111 * The actions to display in the toolbar. defaults to Filter + Create + Export.
108112 *
@@ -193,6 +197,30 @@ export interface ListViewProps {
193197 */
194198 children : ReactNode ;
195199
200+ /**
201+ * A function rendering the list of records. Take the list controller as argument.
202+ *
203+ * @see https://marmelab.com/react-admin/List.html#children
204+ * @example
205+ * import { List } from 'react-admin';
206+ *
207+ * export const BookList = () => (
208+ * <List>
209+ * {(listContext) =>
210+ * listContext.data.map(record => (
211+ * <div key={record.id}>
212+ * <p>{record.id}</p>
213+ * <p>{record.title}</p>
214+ * <p>{record.published_at}</p>
215+ * <p>{record.nb_views}</p>
216+ * </div>
217+ * )
218+ * }
219+ * </List>
220+ * );
221+ */
222+ render ?: ( props : ListControllerResult < RecordType , Error > ) => ReactNode ;
223+
196224 /**
197225 * The component used to display the list. Defaults to <Card>.
198226 *
0 commit comments