diff --git a/src/components/FunctionDefinition.js b/src/components/FunctionDefinition.js index fd56361ac..395b866e2 100644 --- a/src/components/FunctionDefinition.js +++ b/src/components/FunctionDefinition.js @@ -4,10 +4,14 @@ import CodeDef from './CodeDef'; import { graphql } from 'gatsby'; const FunctionDefinition = ({ className, arguments: params, returnValue }) => { - if (!params.length && !returnValue.length) { + if (!params.length && !returnValue && !returnValue.length) { return null; } + if (!Array.isArray(returnValue)) { + returnValue = [returnValue]; + } + return ( function{' '} @@ -30,7 +34,7 @@ const FunctionDefinition = ({ className, arguments: params, returnValue }) => { {params.length > 0 && )} {returnValue.length > 0 && ( <> - => + => {returnValue[0].type} )} @@ -38,6 +42,11 @@ const FunctionDefinition = ({ className, arguments: params, returnValue }) => { ); }; +const ReturnValueType = PropTypes.shape({ + type: PropTypes.string, + description: PropTypes.string, +}); + FunctionDefinition.propTypes = { className: PropTypes.string, arguments: PropTypes.arrayOf( @@ -47,12 +56,10 @@ FunctionDefinition.propTypes = { description: PropTypes.string, }) ).isRequired, - returnValue: PropTypes.arrayOf( - PropTypes.shape({ - type: PropTypes.string, - description: PropTypes.string, - }) - ).isRequired, + returnValue: PropTypes.oneOfType([ + ReturnValueType, + PropTypes.arrayOf(ReturnValueType), + ]).isRequired, }; export const query = graphql`