pre-installations and preparations
This commit is contained in:
1 parent
3e5a0329cb
commit
201d621ac3
6977 files changed
+742826
No files matched your search
+1
@@ -0,0 +1 @@
|
||||
export { default } from './requirePropFactory';
|
||||
+1
@@ -0,0 +1 @@
|
||||
export { default } from './requirePropFactory';
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "./index.js",
|
||||
"main": "../node/requirePropFactory/index.js",
|
||||
"types": "./index.d.ts"
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import * as React from 'react';
|
||||
|
||||
export default function requirePropFactory(
|
||||
componentNameInError: string,
|
||||
Component?: React.JSXElementConstructor<unknown>,
|
||||
): any;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
export default function requirePropFactory(componentNameInError, Component) {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
return () => null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react/forbid-foreign-prop-types
|
||||
const prevPropTypes = Component ? _extends({}, Component.propTypes) : null;
|
||||
const requireProp = requiredProp => (props, propName, componentName, location, propFullName, ...args) => {
|
||||
const propFullNameSafe = propFullName || propName;
|
||||
const defaultTypeChecker = prevPropTypes == null ? void 0 : prevPropTypes[propFullNameSafe];
|
||||
if (defaultTypeChecker) {
|
||||
const typeCheckerResult = defaultTypeChecker(props, propName, componentName, location, propFullName, ...args);
|
||||
if (typeCheckerResult) {
|
||||
return typeCheckerResult;
|
||||
}
|
||||
}
|
||||
if (typeof props[propName] !== 'undefined' && !props[requiredProp]) {
|
||||
return new Error(`The prop \`${propFullNameSafe}\` of ` + `\`${componentNameInError}\` can only be used together with the \`${requiredProp}\` prop.`);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return requireProp;
|
||||
}
|
||||
Reference in new issue
Block a user