-
Notifications
You must be signed in to change notification settings - Fork 2
requirePropFactory updates #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| export default function requirePropFactory(componentNameInError: string): any; | ||
| type Component = (arg: any) => any & { propTypes?: object }; | ||
|
|
||
| export default function requirePropFactory(componentNameInError: string, Component?: Component): any; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export default function requirePropFactory(componentNameInError) { | ||
| export default function requirePropFactory(componentNameInError, Component) { | ||
| if (process.env.NODE_ENV === 'production') { | ||
| return () => null; | ||
| } | ||
|
|
@@ -12,14 +12,22 @@ export default function requirePropFactory(componentNameInError) { | |
| ) => { | ||
| const propFullNameSafe = propFullName || propName; | ||
|
|
||
| const defaultPropType = Component?.propTypes?.[propFullNameSafe]; | ||
| let defaultPropTypeVal = null; | ||
|
|
||
| if(defaultPropType) { | ||
| console.log("Default prop type existed"); | ||
| defaultPropTypeVal = defaultPropType(props, propName, componentName, location, propFullName) | ||
| } | ||
|
|
||
|
||
| 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 defaultPropTypeVal; | ||
| }; | ||
| return requireProp; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.