question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@storybook/addon-info@4.1.4 Error on PropTypes.oneOfType when argument is a var

See original GitHub issue

Describe the bug Addon-info throws an exception (when a story is rendered) if a mounted component defines a PropTypes.oneOfType as a variable rather than an array literal.

To Reproduce Steps to reproduce the behavior:

  1. Import the Test.jsx component into a story and render
  2. run storybook
  3. Load created story

Expected behavior The component renders without error

Actual behavior

  • Story does not render
  • Exception message displayed:
propTypes.map is not a function
    TypeError: propTypes.map is not a function
    at OneOfType (OneOfType.js:27)
    at mountIndeterminateComponent (react-dom.development.js:14811)
    at beginWork (react-dom.development.js:15316)
    at performUnitOfWork (react-dom.development.js:18150)
    at workLoop (react-dom.development.js:18190)
    at HTMLUnknownElement.callCallback (react-dom.development.js:149)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:199)
    at invokeGuardedCallback (react-dom.development.js:256)
    at replayUnitOfWork (react-dom.development.js:17437)

The exception occurs at: https://github.com/storybooks/storybook/blob/4c757d05f162925217751bb5d61518c108d0935b/addons/info/src/components/types/OneOfType.js#L10-L11 where propTypes is expected to be an iterable (either an array of propType, or an object of name “custom”). In this case the value is the string name of the variable passed to PropTypes.oneOfType in the Component - in this case “b”.

Code snippets Test.jsx

import React from 'react';
import PropTypes from 'prop-types';


const Test = ({ a, b }) => <div> {a} {b} </div>;

const allowedChildTypes = [
  PropTypes.number,
  PropTypes.string,
  PropTypes.element,
];

Test.propTypes = {
  // works ok
  a: PropTypes.oneOfType([
    PropTypes.number,
    PropTypes.string,
    PropTypes.element,
  ]),
  // fails with: TypeError: propTypes.map is not a function
  b: PropTypes.oneOfType(allowedChildTypes),
};

export default Test;

System:

  • OS: MacOS
  • Device: Macbook Pro 2018
  • Browser: chrome
  • Framework: react@16.7.0
  • Version: [e.g. 4.1.4]

Additional context It is valid and desirable to use variables as arguments to oneOfType. Its likely that the problem is with react-dom passing the propTypes as a string. However the plugin should guard against the exception and at a minimum report the propType as “custom” or “unknown”.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
johnhuntercommented, Mar 17, 2019

Upgrade to 5.0.1 resolved this issue. With the given example Test.jsx both property ‘a’ and ‘b’ report propType as ‘other’.

Great work on SB5 - thanks!

0reactions
johnhuntercommented, Feb 28, 2019

Thanks @shilman much appreciated - i’m looking forward to seeing SB5. Not able to get to a fix at the moment, will let you know if I do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@storybook/addon-info@4.1.4 Error on PropTypes.oneOfType ...
@storybook/addon-info@4.1.4 Error on PropTypes.oneOfType when argument is a var #5206 ... The component renders without error.
Read more >
PropType.shape({}) Failure Warning: Invalid Type
So we have a change of type here, which generate the warning. When you use sDate: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).
Read more >
Don't Call PropTypes Warning - React
Don't call PropTypes directly. Using PropTypes in any other way than annotating React components with them is no longer supported: var apiShape =...
Read more >
How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >
Type-Checking in React: PropTypes | by Chidume Nnamdi
The component takes an annual salary in the props argument. ... it can never be changed, trying to change it will throw an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found