ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
22 lines (20 loc) • 995 B
JavaScript
import * as React from 'react';
const checkMinimumRequiredProps = (displayName, requiredProps) => (WrappedComponent) => (props) => {
useCheckMinimumRequiredProps(displayName, requiredProps, props);
return React.createElement(WrappedComponent, { ...props });
};
export default checkMinimumRequiredProps;
// Not a hook but named that way to avoid conflicts with the old one
export const useCheckMinimumRequiredProps = (displayName, requiredProps, props) => {
const propNames = Object.keys(props);
const missingProps = requiredProps.filter(prop => !propNames.includes(prop));
if (missingProps.length > 0) {
throw new Error(`<${displayName}> component is not properly configured, some essential props are missing.
Be sure to pass the props from the parent. Example:
const My${displayName} = props => (
<${displayName} {...props}></${displayName}>
);
The missing props are: ${missingProps.join(', ')}`);
}
};
//# sourceMappingURL=checkMinimumRequiredProps.js.map