Skip to content

Commit

Permalink
Fix: Fix a crash when default prop value isn't a string (#1510)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazyuki authored and sapegin committed Jan 6, 2020
1 parent c1e25cf commit 626e505
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit 626e505

Please sign in to comment.