Skip to content

Commit 1d615df

Browse files
committed
Update documentation
1 parent 9c821ba commit 1d615df

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

docs/List.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,12 +1190,27 @@ export const PostList = () => (
11901190
}
11911191
}}
11921192
>
1193-
{/* DataGrid */}
1193+
<WithListContext
1194+
render={context =>
1195+
context.filterValues.q == null ||
1196+
context.filterValues.q === '' ? (
1197+
<CardContentInner>
1198+
Type a search term to fetch data
1199+
</CardContentInner>
1200+
) : (
1201+
<Datagrid>
1202+
{/* your fields */}
1203+
</Datagrid>
1204+
)
1205+
}
1206+
/>
11941207
</List>
11951208
)
11961209
```
11971210
{% endraw %}
11981211

1212+
**Note**: Notice we display some custom UI when there is no filter. This is because otherwise, users would see the loading UI as Tanstack Query will set the `isPending` property of the underlying query to `true` if the query isn't enabled.
1213+
11991214
## Accessing Extra Response Data
12001215

12011216
If `dataProvider.getList()` returns additional metadata in the response under the `meta` key, you can access it in the list view using the `meta` property of the `ListContext`.

packages/ra-ui-materialui/src/list/List.stories.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
TestMemoryRouter,
88
DataProvider,
99
GetListParams,
10+
WithListContext,
1011
} from 'ra-core';
1112
import fakeRestDataProvider from 'ra-data-fakerest';
1213
import {
@@ -253,28 +254,25 @@ export const ConditionalDataFetching = () => (
253254
},
254255
}}
255256
>
256-
<ConditionalDataFetchingView />
257+
<WithListContext
258+
render={context =>
259+
context.filterValues.q == null ||
260+
context.filterValues.q === '' ? (
261+
<CardContentInner>
262+
Type a search term to fetch data
263+
</CardContentInner>
264+
) : (
265+
<BookList />
266+
)
267+
}
268+
/>
257269
</List>
258270
)}
259271
/>
260272
</Admin>
261273
</TestMemoryRouter>
262274
);
263275

264-
const ConditionalDataFetchingView = () => {
265-
const context = useListContext();
266-
267-
if (context.filterValues.q == null || context.filterValues.q === '') {
268-
return (
269-
<CardContentInner>
270-
Type a search term to fetch data
271-
</CardContentInner>
272-
);
273-
}
274-
275-
return <BookList />;
276-
};
277-
278276
export const Filter = () => (
279277
<TestMemoryRouter initialEntries={['/books']}>
280278
<Admin dataProvider={defaultDataProvider}>

0 commit comments

Comments
 (0)