better-docs
better-docs copied to clipboard
TypeError: Cannot read property 'name' of undefined
Hi, When I pass default props in React functional component like in this example:
/**
* Component renders input field of profile image.
*
* @name ProfileImage
* @component
* @example
* const id = 'avatar'
* const label = 'Profile image'
* const type = 'profileimage'
* const withFeedbackLabel = true
* return (
* <ProfileImage id={id} label={label} type={type} withFeedbackLabel={withFeedbackLabel} />
* );
*/
export default function ProfileImage({ id, label, type, withFeedbackLabel = true }) {
I get an error like this:
/mnt/e/Projekty/www/core-react/node_modules/better-docs/component.js:81 type: prop.type ? prop.type.name : prop.flowType.name, ^
TypeError: Cannot read property 'name' of undefined
When I dont pass default withFeedbackLabel = true and pass default withFeedbackLabel without default, everything working fine.
ok I see the code - it is a bug. You can add PropTypes to fix that right now
I have the same issue.
By putting a console.log('PROP', key, prop) on component.ts:73, gives me:
PROP badgeProps { defaultValue: { value: '{}', computed: false }, required: false }
Neither type nor flowType is present on this object.
Checking the existence of flowType on line 75, changing it from type: prop.type ? prop.type.name : prop.flowType.name to type: prop.type ? prop.type.name : prop.flowType?.name seems to fix it, but I don know if there are any side effects.
Is there a reason for this bug ? I don't use types. Maybe it's caused by the fact I don't add the "@ name" ?
Any updates? Still reproduce
It's likely an issue with a misnamed property. For myself, my default property declaration was mistyped.
ok I see the code - it is a bug. You can add PropTypes to fix that right now
How do I do this exactly? I seem to set the "defaultProps" but it fails still.
like Component.defaultProps = { field: value}