better-docs icon indicating copy to clipboard operation
better-docs copied to clipboard

TypeError: Cannot read property 'name' of undefined

Open kszymczycha opened this issue 5 years ago • 6 comments

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.

kszymczycha avatar Oct 09 '20 08:10 kszymczycha

ok I see the code - it is a bug. You can add PropTypes to fix that right now

wojtek-krysiak avatar Oct 11 '20 04:10 wojtek-krysiak

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.

pedrobernardina avatar Mar 03 '21 19:03 pedrobernardina

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" ?

Eliepse avatar Mar 23 '21 15:03 Eliepse

Any updates? Still reproduce

fofyga avatar Jun 11 '21 09:06 fofyga

It's likely an issue with a misnamed property. For myself, my default property declaration was mistyped.

VizualAbstract avatar Jun 13 '21 21:06 VizualAbstract

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}

briantical avatar Aug 05 '21 15:08 briantical