Skip to content

Commit

Permalink
feat: Use getDefaultValue helper in useComponentDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 6, 2020
1 parent 80485ed commit f40c603
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/hooks/useComponentDoc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useMemo } from 'react';
import { SPECIAL_NUMBERS } from '../utils/propConstants';
import { getNormalizedTypeName, getRawTypeName } from '../utils/propTypeInfo';
import {
getDefaultValue,
getNormalizedTypeName,
getRawTypeName,
} from '../utils/propTypeInfo';

const IGNORED_METHODS = [
'prototype',
Expand All @@ -18,13 +22,6 @@ const extractPropTypes = (component) => {

const type = processType(component, name, propMeta);

const defaultValue = getDefaultValue(
component,
name,
type.isOneOf,
toStaticName(name)
);

return {
name,
description: propDocs.text,
Expand All @@ -33,7 +30,7 @@ const extractPropTypes = (component) => {
raw: getRawTypeName(propType),
name: getNormalizedTypeName(propType),
},
defaultValue,
defaultValue: getDefaultValue(component, name),
};
});
};
Expand All @@ -50,7 +47,7 @@ const processPropType = (component, propName, prop) => {
const type = processType(component, propName, propMeta);

const staticName = toStaticName(propName);
const defaultValue = getDefaultValue(
const defaultValue = getDefaultValue_REPLACE_ME(
component,
propName,
type.isOneOf,
Expand Down Expand Up @@ -142,7 +139,12 @@ const processType = (component, propName, propMeta) => {
};

// TODO: refactor: remove let? earlier / opportunistic returns?
const getDefaultValue = (component, propName, isOneOf, staticName) => {
const getDefaultValue_REPLACE_ME = (
component,
propName,
isOneOf,
staticName
) => {
let defaultValue = component?.defaultProps?.[propName];

const isArray = Array.isArray(defaultValue);
Expand Down

0 comments on commit f40c603

Please sign in to comment.