Skip to content

Commit 03cae57

Browse files
[Chore]: Update ra-core to use ReactNode instead of ReactElement where applicable
1 parent c27492d commit 03cae57

File tree

10 files changed

+22
-26
lines changed

10 files changed

+22
-26
lines changed

docs_headless/src/content/docs/ReferenceOneInputBase.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ const BookEdit = () => (
5858
| `reference` | Required | `string` | - | The name of the resource for the referenced records, e.g. 'book_details' |
5959
| `children` | Optional | `Element` | - | 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() |

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/record/OptionalRecordContextProvider.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { ReactElement } from 'react';
32
import { RaRecord } from '../../types';
43
import { RecordContextProvider } from './RecordContext';
54

@@ -24,7 +23,7 @@ export const OptionalRecordContextProvider = <
2423
value,
2524
children,
2625
}: {
27-
children: ReactElement;
26+
children: React.ReactNode;
2827
value?: RecordType;
2928
}) =>
3029
value ? (

packages/ra-core/src/core/CoreAdminUI.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
createElement,
77
useState,
88
ErrorInfo,
9-
ReactElement,
109
} from 'react';
1110
import { Routes, Route } from 'react-router-dom';
1211
import { ErrorBoundary } from 'react-error-boundary';
@@ -154,7 +153,7 @@ export interface CoreAdminUIProps {
154153
errorInfo?: ErrorInfo;
155154
error: Error;
156155
resetErrorBoundary: (args) => void;
157-
}) => ReactElement;
156+
}) => React.ReactNode;
158157

159158
/**
160159
* The main app layout component

packages/ra-core/src/core/useResourceDefinition.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import defaults from 'lodash/defaults';
33

44
import { useResourceDefinitions } from './useResourceDefinitions';
55
import { useResourceContext } from './useResourceContext';
6-
import { ResourceDefinition, ResourceOptions } from '../types';
6+
import {
7+
RecordToStringFunction,
8+
ResourceDefinition,
9+
ResourceOptions,
10+
} from '../types';
711

812
/**
913
* Hook to get the definition of a given resource
@@ -67,8 +71,5 @@ export interface UseResourceDefinitionOptions {
6771
readonly hasEdit?: boolean;
6872
readonly hasShow?: boolean;
6973
readonly hasCreate?: boolean;
70-
readonly recordRepresentation?:
71-
| string
72-
| React.ReactElement
73-
| ((record: any) => string);
74+
readonly recordRepresentation?: React.ReactNode | RecordToStringFunction;
7475
}

packages/ra-core/src/i18n/TranslatableContextProvider.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { ReactElement, ReactNode } from 'react';
32
import {
43
TranslatableContext,
54
TranslatableContextValue,
@@ -9,9 +8,9 @@ export const TranslatableContextProvider = ({
98
children,
109
value,
1110
}: {
12-
children: ReactNode;
11+
children: React.ReactNode;
1312
value: TranslatableContextValue;
14-
}): ReactElement => {
13+
}): React.ReactNode => {
1514
return (
1615
<TranslatableContext.Provider value={value}>
1716
{children}

packages/ra-core/src/preferences/PreferencesEditorContext.tsx

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

44
export const PreferencesEditorContext = createContext<
55
PreferencesEditorContextValue | undefined
66
>(undefined);
77

88
export type PreferencesEditorContextValue = {
9-
editor: ReactElement | null;
10-
setEditor: React.Dispatch<React.SetStateAction<ReactElement | null>>;
9+
editor: React.ReactNode;
10+
setEditor: React.Dispatch<React.SetStateAction<React.ReactNode>>;
1111
preferenceKey: string | null;
1212
setPreferenceKey: React.Dispatch<React.SetStateAction<string | null>>;
1313
title: string | null;

packages/ra-core/src/preferences/PreferencesEditorContextProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as React from 'react';
2-
import { ReactElement, useCallback, useMemo, useState } from 'react';
2+
import { useCallback, useMemo, useState } from 'react';
33
import {
44
PreferencesEditorContext,
55
PreferencesEditorContextValue,
66
} from './PreferencesEditorContext';
77

88
export const PreferencesEditorContextProvider = ({ children }) => {
99
const [isEnabled, setIsEnabled] = useState(false);
10-
const [editor, setEditor] = useState<ReactElement | null>(null);
10+
const [editor, setEditor] = useState<React.ReactNode>(null);
1111
const [preferenceKey, setPreferenceKey] = useState<string | null>(null);
1212
const [path, setPath] = useState<string | null>(null);
1313
const [title, setTitleString] = useState<string | null>(null);

packages/ra-core/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ export type AdminChildren =
343343
| Iterable<ReactNode | RenderResourcesFunction>
344344
| ReactNode;
345345

346-
export type TitleComponent = string | ReactElement<any>;
346+
export type TitleComponent = ReactNode;
347347
export type CatchAllComponent = ComponentType<{ title?: TitleComponent }>;
348348

349-
export type LoginComponent = ComponentType<{}> | ReactElement<any>;
349+
export type LoginComponent = ComponentType<{}> | ReactNode;
350350
export type DashboardComponent = ComponentType<WithPermissionsChildrenParams>;
351351

352352
export interface CoreLayoutProps {

packages/ra-core/src/util/FieldTitle.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ export const FieldTitle = (props: FieldTitleProps) => {
1515
const translateLabel = useTranslateLabel();
1616

1717
if (label === true) {
18-
throw new Error(
19-
'Label parameter must be a string, a ReactElement or false'
20-
);
18+
throw new Error('Label parameter must be a ReactNode');
2119
}
2220

2321
if (label === false || label === '') {

0 commit comments

Comments
 (0)