Skip to content

Commit a033ba6

Browse files
authored
Merge pull request #6515 from WiXSL/remove-fc-core
[RFR] Remove FC usage from `ra-core` components
2 parents 8010aeb + 89e5673 commit a033ba6

20 files changed

+164
-212
lines changed

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cloneElement, ReactElement, FunctionComponent } from 'react';
1+
import { cloneElement, ReactElement } from 'react';
22

33
import useAuthenticated from './useAuthenticated';
44

@@ -36,12 +36,13 @@ interface Props {
3636
* </Admin>
3737
* );
3838
*/
39-
const Authenticated: FunctionComponent<Props> = ({
40-
authParams,
41-
children,
42-
location, // kept for backwards compatibility, unused
43-
...rest
44-
}) => {
39+
const Authenticated = (props: Props) => {
40+
const {
41+
authParams,
42+
children,
43+
location, // kept for backwards compatibility, unused
44+
...rest
45+
} = props;
4546
useAuthenticated(authParams);
4647
// render the child even though the useAuthenticated() call isn't finished (optimistic rendering)
4748
// the above hook will log out if the authProvider doesn't validate that the user is authenticated

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

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Children,
3-
FunctionComponent,
4-
ReactElement,
5-
ComponentType,
6-
createElement,
7-
} from 'react';
1+
import { Children, ReactElement, ComponentType, createElement } from 'react';
82
import { Location } from 'history';
93

104
import warning from '../util/warning';
@@ -65,14 +59,15 @@ const isEmptyChildren = children => Children.count(children) === 0;
6559
* </Admin>
6660
* );
6761
*/
68-
const WithPermissions: FunctionComponent<Props> = ({
69-
authParams,
70-
children,
71-
render,
72-
component,
73-
staticContext,
74-
...props
75-
}) => {
62+
const WithPermissions = (props: Props) => {
63+
const {
64+
authParams,
65+
children,
66+
render,
67+
component,
68+
staticContext,
69+
...rest
70+
} = props;
7671
warning(
7772
(render && children && !isEmptyChildren(children)) ||
7873
(render && component) ||
@@ -84,15 +79,15 @@ const WithPermissions: FunctionComponent<Props> = ({
8479
const { permissions } = usePermissionsOptimized(authParams);
8580
// render even though the usePermissions() call isn't finished (optimistic rendering)
8681
if (component) {
87-
return createElement(component, { permissions, ...props });
82+
return createElement(component, { permissions, ...rest });
8883
}
8984
// @deprecated
9085
if (render) {
91-
return render({ permissions, ...props });
86+
return render({ permissions, ...rest });
9287
}
9388
// @deprecated
9489
if (children) {
95-
return children({ permissions, ...props });
90+
return children({ permissions, ...rest });
9691
}
9792
};
9893

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FunctionComponent, ReactElement } from 'react';
1+
import { ReactElement } from 'react';
22

33
import useReferenceArrayFieldController from './useReferenceArrayFieldController';
44
import { ListControllerProps } from '../useListController';
@@ -22,7 +22,7 @@ interface Props {
2222
*
2323
* @see useReferenceArrayFieldController
2424
*/
25-
const ReferenceArrayFieldController: FunctionComponent<Props> = props => {
25+
const ReferenceArrayFieldController = (props: Props) => {
2626
const { children, ...rest } = props;
2727
const controllerProps = useReferenceArrayFieldController({
2828
sort: {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FunctionComponent, ReactNode, ReactElement } from 'react';
1+
import { ReactNode, ReactElement } from 'react';
22
import get from 'lodash/get';
33

44
import { Record } from '../../types';
@@ -49,12 +49,12 @@ interface Props {
4949
* <TextField source="name" />
5050
* </ReferenceField>
5151
*/
52-
export const ReferenceFieldController: FunctionComponent<Props> = ({
52+
export const ReferenceFieldController = ({
5353
children,
5454
record,
5555
source,
5656
...props
57-
}) => {
57+
}: Props) => {
5858
const id = get(record, source);
5959
return children({
6060
...useReference({ ...props, id }),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactElement, FunctionComponent } from 'react';
1+
import { ReactElement } from 'react';
22

33
import { Record, SortPayload } from '../../types';
44
import useReferenceManyFieldController from './useReferenceManyFieldController';
@@ -24,7 +24,7 @@ interface Props {
2424
*
2525
* @see useReferenceManyFieldController
2626
*/
27-
export const ReferenceManyFieldController: FunctionComponent<Props> = props => {
27+
export const ReferenceManyFieldController = (props: Props) => {
2828
const { children, page = 1, perPage = 25, ...rest } = props;
2929
const controllerProps = useReferenceManyFieldController({
3030
page,

packages/ra-core/src/controller/input/ReferenceInputController.tsx

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
ReactNode,
3-
ComponentType,
4-
FunctionComponent,
5-
ReactElement,
6-
} from 'react';
1+
import { ReactNode, ComponentType, ReactElement } from 'react';
72

83
import { SortPayload, Record } from '../../types';
94
import {
@@ -33,11 +28,9 @@ interface Props {
3328
*
3429
* @see useReferenceInputController
3530
*/
36-
export const ReferenceInputController: FunctionComponent<Props> = ({
37-
children,
38-
...props
39-
}) => {
40-
return children(useReferenceInputController(props)) as ReactElement;
31+
export const ReferenceInputController = (props: Props) => {
32+
const { children, ...rest } = props;
33+
return children(useReferenceInputController(rest)) as ReactElement;
4134
};
4235

4336
export default ReferenceInputController as ComponentType<Props>;

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

+24-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { FunctionComponent, ComponentType } from 'react';
2+
import { ComponentType } from 'react';
33

44
import CoreAdminContext from './CoreAdminContext';
55
import CoreAdminUI from './CoreAdminUI';
@@ -86,28 +86,29 @@ export type ChildrenFunction = () => ComponentType[];
8686
* );
8787
* };
8888
*/
89-
const CoreAdmin: FunctionComponent<AdminProps> = ({
90-
appLayout,
91-
authProvider,
92-
catchAll,
93-
children,
94-
customReducers,
95-
customRoutes = [],
96-
customSagas,
97-
dashboard,
98-
dataProvider,
99-
disableTelemetry,
100-
history,
101-
i18nProvider,
102-
initialState,
103-
layout,
104-
loading,
105-
loginPage,
106-
logoutButton,
107-
menu, // deprecated, use a custom layout instead
108-
theme,
109-
title = 'React Admin',
110-
}) => {
89+
const CoreAdmin = (props: AdminProps) => {
90+
const {
91+
appLayout,
92+
authProvider,
93+
catchAll,
94+
children,
95+
customReducers,
96+
customRoutes = [],
97+
customSagas,
98+
dashboard,
99+
dataProvider,
100+
disableTelemetry,
101+
history,
102+
i18nProvider,
103+
initialState,
104+
layout,
105+
loading,
106+
loginPage,
107+
logoutButton,
108+
menu, // deprecated, use a custom layout instead
109+
theme,
110+
title = 'React Admin',
111+
} = props;
111112
return (
112113
<CoreAdminContext
113114
authProvider={authProvider}

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

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { FunctionComponent, ComponentType, useContext, useState } from 'react';
2+
import { ComponentType, useContext, useState } from 'react';
33
import { Provider, ReactReduxContext } from 'react-redux';
44
import { History } from 'history';
55
import { createHashHistory } from 'history';
@@ -40,16 +40,17 @@ export interface AdminContextProps {
4040
theme?: object;
4141
}
4242

43-
const CoreAdminContext: FunctionComponent<AdminContextProps> = ({
44-
authProvider,
45-
dataProvider,
46-
i18nProvider,
47-
children,
48-
history,
49-
customReducers,
50-
customSagas,
51-
initialState,
52-
}) => {
43+
const CoreAdminContext = (props: AdminContextProps) => {
44+
const {
45+
authProvider,
46+
dataProvider,
47+
i18nProvider,
48+
children,
49+
history,
50+
customReducers,
51+
customSagas,
52+
initialState,
53+
} = props;
5354
const reduxIsAlreadyInitialized = !!useContext(ReactReduxContext);
5455

5556
if (!dataProvider) {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import React, {
55
createElement,
66
ComponentType,
77
ReactElement,
8-
FunctionComponent,
98
} from 'react';
109
import { Route, Switch } from 'react-router-dom';
1110

@@ -36,7 +35,7 @@ export interface AdminRouterProps extends CoreLayoutProps {
3635

3736
type State = ResourceElement[];
3837

39-
const CoreAdminRouter: FunctionComponent<AdminRouterProps> = props => {
38+
const CoreAdminRouter = (props: AdminRouterProps) => {
4039
const getPermissions = useGetPermissions();
4140
const doLogout = useLogout();
4241
const { authenticated } = useAuthState();

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

+19-25
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import * as React from 'react';
2-
import {
3-
createElement,
4-
FunctionComponent,
5-
ComponentType,
6-
useMemo,
7-
useEffect,
8-
} from 'react';
2+
import { createElement, ComponentType, useMemo, useEffect } from 'react';
93
import { Switch, Route } from 'react-router-dom';
104

115
import CoreAdminRouter from './CoreAdminRouter';
@@ -24,9 +18,7 @@ import {
2418

2519
export type ChildrenFunction = () => ComponentType[];
2620

27-
const DefaultLayout: FunctionComponent<CoreLayoutProps> = ({ children }) => (
28-
<>{children}</>
29-
);
21+
const DefaultLayout = ({ children }: CoreLayoutProps) => <>{children}</>;
3022

3123
export interface AdminUIProps {
3224
catchAll?: CatchAllComponent;
@@ -47,21 +39,23 @@ export interface AdminUIProps {
4739
// for BC
4840
export type CoreAdminUIProps = AdminUIProps;
4941

50-
const CoreAdminUI: FunctionComponent<AdminUIProps> = ({
51-
catchAll = Noop,
52-
children,
53-
customRoutes = [],
54-
dashboard,
55-
disableTelemetry = false,
56-
layout = DefaultLayout,
57-
loading = Noop,
58-
loginPage = false,
59-
logout,
60-
menu, // deprecated, use a custom layout instead
61-
ready = Ready,
62-
theme,
63-
title = 'React Admin',
64-
}) => {
42+
const CoreAdminUI = (props: AdminUIProps) => {
43+
const {
44+
catchAll = Noop,
45+
children,
46+
customRoutes = [],
47+
dashboard,
48+
disableTelemetry = false,
49+
layout = DefaultLayout,
50+
loading = Noop,
51+
loginPage = false,
52+
logout,
53+
menu, // deprecated, use a custom layout instead
54+
ready = Ready,
55+
theme,
56+
title = 'React Admin',
57+
} = props;
58+
6559
const logoutElement = useMemo(() => logout && createElement(logout), [
6660
logout,
6761
]);

0 commit comments

Comments
 (0)