Skip to content
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

Fix crashes when DefaultProp isn't a string #1510

Merged
merged 2 commits into from
Jan 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/client/rsg-components/Props/renderDefault.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ export default function renderDefault(prop: PropDescriptorWithFlow): React.React
// Workaround for issue https://github.com/reactjs/react-docgen/issues/221
// If prop has defaultValue it can not be required
if (prop.defaultValue) {
const defaultValueString = showSpaces(unquote(String(prop.defaultValue.value)));
if (prop.type || prop.flowType) {
const propName = prop.type ? prop.type.name : prop.flowType && prop.flowType.type;

if (defaultValueBlacklist.indexOf(prop.defaultValue.value) > -1) {
return <Code>{showSpaces(unquote(prop.defaultValue.value))}</Code>;
return <Code>{defaultValueString}</Code>;
} else if (propName === 'func' || propName === 'function') {
return (
<Text
size="small"
color="light"
underlined
title={showSpaces(unquote(prop.defaultValue.value))}
title={defaultValueString}
>
Function
</Text>
Expand Down Expand Up @@ -50,7 +51,7 @@ export default function renderDefault(prop: PropDescriptorWithFlow): React.React
}
}

return <Code>{showSpaces(unquote(prop.defaultValue.value))}</Code>;
return <Code>{defaultValueString}</Code>;
} else if (prop.required) {
return (
<Text size="small" color="light">
Expand Down