diff --git a/packages/ra-core/src/controller/input/index.ts b/packages/ra-core/src/controller/input/index.ts
index 2d84189d5da..7f533494999 100644
--- a/packages/ra-core/src/controller/input/index.ts
+++ b/packages/ra-core/src/controller/input/index.ts
@@ -1,9 +1,11 @@
import ReferenceArrayInputController from './ReferenceArrayInputController';
import ReferenceInputController from './ReferenceInputController';
import useReferenceInputController from './useReferenceInputController';
+import useReferenceArrayInputController from './useReferenceArrayInputController';
export {
ReferenceArrayInputController,
ReferenceInputController,
useReferenceInputController,
+ useReferenceArrayInputController,
};
diff --git a/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js b/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js
index fd9e7619b94..b809d4fb24d 100644
--- a/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js
+++ b/packages/ra-ui-materialui/src/input/ReferenceArrayInput.js
@@ -1,7 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
-import compose from 'recompose/compose';
-import { addField, translate, ReferenceArrayInputController } from 'ra-core';
+import {
+ useReferenceArrayInputController,
+ useInput,
+ useTranslate,
+} from 'ra-core';
import LinearProgress from '../layout/LinearProgress';
import Labeled from '../input/Labeled';
@@ -209,22 +212,48 @@ ReferenceArrayInputView.propTypes = {
*
*
*/
-export const ReferenceArrayInput = ({ children, ...props }) => {
+export const ReferenceArrayInput = ({
+ children,
+ id: idOverride,
+ onBlur,
+ onChange,
+ onFocus,
+ validate,
+ ...props
+}) => {
if (React.Children.count(children) !== 1) {
throw new Error(
' only accepts a single child (like )'
);
}
+ const { id, input, isRequired, meta } = useInput({
+ id: idOverride,
+ onBlur,
+ onChange,
+ onFocus,
+ source: props.source,
+ validate,
+ });
+
+ const controllerProps = useReferenceArrayInputController({
+ ...props,
+ input,
+ });
+
+ const translate = useTranslate();
+
return (
-
- {controllerProps => (
-
- )}
-
+
);
};
@@ -235,18 +264,15 @@ ReferenceArrayInput.propTypes = {
className: PropTypes.string,
filter: PropTypes.object,
filterToQuery: PropTypes.func.isRequired,
- input: PropTypes.object.isRequired,
label: PropTypes.string,
- meta: PropTypes.object,
perPage: PropTypes.number,
reference: PropTypes.string.isRequired,
- resource: PropTypes.string.isRequired,
+ resource: PropTypes.string,
sort: PropTypes.shape({
field: PropTypes.string,
order: PropTypes.oneOf(['ASC', 'DESC']),
}),
source: PropTypes.string,
- translate: PropTypes.func.isRequired,
};
ReferenceArrayInput.defaultProps = {
@@ -257,9 +283,4 @@ ReferenceArrayInput.defaultProps = {
sort: { field: 'id', order: 'DESC' },
};
-const EnhancedReferenceArrayInput = compose(
- addField,
- translate
-)(ReferenceArrayInput);
-
-export default EnhancedReferenceArrayInput;
+export default ReferenceArrayInput;