Skip to content

Commit 0a387f2

Browse files
Chore: Use ReactNode instead of ReactElement where applicable in ra-core
1 parent 491e44d commit 0a387f2

19 files changed

+48
-56
lines changed

docs_headless/src/content/docs/ReferenceArrayFieldBase.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ You can change how the list of related records is rendered by passing a custom c
8383
| -------------- | -------- | --------------------------------------------------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------ |
8484
| `source` | Required | `string` | - | Name of the property to display |
8585
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'tags' |
86-
| `children` | Optional\* | `Element` | | One or several elements that render a list of records based on a `ListContext` |
87-
| `render` | Optional\* | `(ListContext) => Element` | | A function that takes a list context and renders a list of records |
86+
| `children` | Optional\* | `ReactNode` | | One or several elements that render a list of records based on a `ListContext` |
87+
| `render` | Optional\* | `(ListContext) => ReactNode` | | A function that takes a list context and renders a list of records |
8888
| `empty` | Optional | `ReactNode` | - | The component to render when the related records list is empty |
8989
| `error` | Optional | `ReactNode` | - | The component to render when an error occurs while fetching the related records |
9090
| `filter` | Optional | `Object` | - | Filters to use when fetching the related records (the filtering is done client-side) |

docs_headless/src/content/docs/ReferenceManyFieldBase.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ export const PostList = () => (
8888
| -------------- | -------- | --------------------------------------------------------------------------------- | -------------------------------- | ----------------------------------------------------------------------------------- |
8989
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'books' |
9090
| `target` | Required | `string` | - | Target field carrying the relationship on the referenced resource, e.g. 'user_id' |
91-
| `children` | Optional\* | `Element` | - | One or several elements that render a list of records based on a `ListContext` |
92-
| `render` | Optional\* | `(ListContext) => Element` | - | Function that receives a `ListContext` and returns an element |
91+
| `children` | Optional\* | `ReactNode` | - | One or several elements that render a list of records based on a `ListContext` |
92+
| `render` | Optional\* | `(ListContext) => ReactNode` | - | Function that receives a `ListContext` and returns an element |
9393
| `debounce` | Optional | `number` | 500 | debounce time in ms for the `setFilters` callbacks |
9494
| `empty` | Optional | `ReactNode` | - | Element to display when there are no related records. |
9595
| `error` | Optional | `ReactNode` | - | The component to render when an error occurs while fetching the related records |

docs_headless/src/content/docs/ReferenceManyInputBase.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const ProductEdit = () => (
6868
| ----------------- | -------- | ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6969
| `target` | Required | `string` | - | Target field carrying the relationship on the referenced resource, e.g. 'user_id' |
7070
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'books' |
71-
| `children` | Optional | `Element` | - | One or several elements that render a list of records based on a `ListContext` |
71+
| `children` | Optional | `ReactNode` | - | One or several elements that render a list of records based on a `ListContext` |
7272
| `defaultValue` | Optional | `array` | - | Default value of the input. |
7373
| `filter` | Optional | `Object` | - | Filters to use when fetching the related records, passed to `getManyReference()` |
7474
| `mutationOptions` | Optional | `UseMutationOptions` | - | Options for the mutations (`create`, `update` and `delete`) |

docs_headless/src/content/docs/ReferenceOneFieldBase.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ const BookDetails = () => {
6969
| -------------- | ---------- | -------------------------------------------------------------------------------- | ------------------------------- | --------------------------------------------------------------------------------- |
7070
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'book_details' |
7171
| `target` | Required | string | - | Target field carrying the relationship on the referenced resource, e.g. 'book_id' |
72-
| `children` | Optional\* | `Element` | - | React component to render the referenced record. |
73-
| `render` | Optional\* | `(ReferenceFieldContext) => Element` | - | A function that takes the `ReferenceFieldContext` and return a React element |
72+
| `children` | Optional\* | `ReactNode` | - | React component to render the referenced record. |
73+
| `render` | Optional\* | `(ReferenceFieldContext) => ReactNode` | - | A function that takes the `ReferenceFieldContext` and return a React element |
7474
| `empty` | Optional | `ReactNode` | - | The text or element to display when the referenced record is empty |
7575
| `filter` | Optional | `Object` | `{}` | Used to filter referenced records |
7676
| `link` | Optional | `string | Function` | `edit` | Target of the link wrapping the rendered child. Set to `false` to disable the link. |

docs_headless/src/content/docs/ReferenceOneInputBase.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ const BookEdit = () => (
5656
| ----------------- | -------- | -------------------- | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5757
| `target` | Required | `string` | - | Target field carrying the relationship on the referenced resource, e.g. 'book_id' |
5858
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'book_details' |
59-
| `children` | Optional | `Element` | - | One or several input elements that accept a `source` prop |
59+
| `children` | Optional | `ReactNode` | - | One or several input elements that accept a `source` prop |
6060
| `defaultValue` | Optional | `Object` | - | Default value for the related record (in case it does not yet exist) |
61-
| `error` | Optional | `Element` | - | The element to display when an error occurs while loading a reference |
61+
| `error` | Optional | `ReactNode` | - | The element to display when an error occurs while loading a reference |
6262
| `filter` | Optional | `Object` | - | Filters to use when fetching the related record, passed to `getManyReference() |
63-
| `loading` | Optional | `Element` | - | The element to display while loading a reference |
63+
| `loading` | Optional | `ReactNode` | - | The element to display while loading a reference |
6464
| `mutationOptions` | Optional | `UseMutationOptions` | - | Options for the mutations (`create` and `update`) |
6565
| `render` | Optional | `Function` | - | A function that returns the children to display. Takes precedence over `children` |
6666
| `sort` | Optional | `{ field, order }` | `{ field: 'id', order: 'ASC' }` | Sort order to use when fetching the related record, passed to `getManyReference() |

docs_headless/src/content/docs/SimpleFormIteratorBase.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ const AddItemButton = () => {
6767

6868
| Prop | Required | Type | Default | Description |
6969
|-------------------|----------|----------------|-----------------------|-----------------------------------------------|
70-
| `children` | Optional | `ReactElement` | - | List of inputs to display for each array item |
70+
| `children` | Optional | `ReactNode` | - | List of inputs to display for each array item |

packages/ra-core/src/auth/WithPermissions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Children, ReactElement, ComponentType, createElement } from 'react';
2+
import { Children, ComponentType, createElement } from 'react';
33
import { Location } from 'react-router-dom';
44

55
import warning from '../util/warning';
@@ -12,7 +12,7 @@ export interface WithPermissionsChildrenParams {
1212

1313
type WithPermissionsChildren = (
1414
params: WithPermissionsChildrenParams
15-
) => ReactElement;
15+
) => React.ReactNode;
1616

1717
export interface WithPermissionsProps {
1818
authParams?: object;

packages/ra-core/src/controller/field/ReferenceArrayFieldBase.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { type ReactElement, type ReactNode } from 'react';
2+
import { type ReactNode } from 'react';
33

44
import type { UseQueryOptions } from '@tanstack/react-query';
55
import { FilterPayload, RaRecord, SortPayload } from '../../types';
@@ -170,7 +170,9 @@ export interface ReferenceArrayFieldBaseProps<
170170
ReferenceRecordType extends RaRecord = RaRecord,
171171
> extends BaseFieldProps<RecordType> {
172172
children?: ReactNode;
173-
render?: (props: ListControllerResult<ReferenceRecordType>) => ReactElement;
173+
render?: (
174+
props: ListControllerResult<ReferenceRecordType>
175+
) => React.ReactNode;
174176
error?: ReactNode;
175177
loading?: ReactNode;
176178
empty?: ReactNode;

packages/ra-core/src/controller/input/useReferenceArrayInputController.spec.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import { CoreAdminContext } from '../../core';
1111
import { testDataProvider } from '../../dataProvider';
1212
import { ChoicesContextValue, Form } from '../../form';
1313
import { SORT_ASC } from '../list/queryReducer';
14+
import { GetManyResult, RaRecord } from '../../types';
1415

1516
const ReferenceArrayInputController = (
1617
props: UseReferenceArrayInputParams & {
18+
field: { value: any };
1719
children: (params: ChoicesContextValue) => ReactElement;
1820
}
1921
) => {
@@ -157,7 +159,7 @@ describe('useReferenceArrayInputController', () => {
157159
getMany: () =>
158160
Promise.resolve({
159161
data: [{ id: 1, title: 'foo' }],
160-
}),
162+
} satisfies GetManyResult<RaRecord> as any),
161163
})}
162164
>
163165
<Form onSubmit={jest.fn()}>
@@ -545,11 +547,7 @@ describe('useReferenceArrayInputController', () => {
545547
});
546548

547549
it('should have props compatible with the ListContext', async () => {
548-
const children = ({
549-
setPage,
550-
setPerPage,
551-
setSort,
552-
}): React.ReactElement => {
550+
const children = ({ setPage, setPerPage, setSort }) => {
553551
const handleSetPage = () => {
554552
setPage(2);
555553
};

packages/ra-core/src/controller/input/useReferenceInputController.spec.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { useState, useCallback, ReactElement } from 'react';
2+
import { useState, useCallback } from 'react';
33
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
44
import expect from 'expect';
55

@@ -21,9 +21,7 @@ const ReferenceInputController = (
2121
const inputProps = useInput({
2222
...rest,
2323
});
24-
return children(
25-
useReferenceInputController({ ...rest, ...inputProps })
26-
) as ReactElement;
24+
return children(useReferenceInputController({ ...rest, ...inputProps }));
2725
};
2826

2927
describe('useReferenceInputController', () => {

0 commit comments

Comments
 (0)