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.

Prop table broken in 5.3.2 with propTypes

See original GitHub issue

Describe the bug On upgrading to 5.3.2, any props defined with propTypes are not building the prop table

To Reproduce Declare propTypes for a component. Open storybook and see that it hasn’t generated a prop table.

Expected behavior Expected to see prop information

Screenshots

Before

image

After upgrading

image

Code snippets

class Dropdown extends React.Component {
  constructor() {
    super()
    this.state = { show_action_sheet: false }
    this.toggleActionSheet = this.toggleActionSheet.bind(this)
  }

  toggleActionSheet() {
    this.setState({ show_action_sheet: !this.state.show_action_sheet })
  }

  render() {
    const {
      split,
    } = this.props

    const isMobile = detectMobile()

    let DropdownComponent

    if (split) {
      DropdownComponent = isMobile ? SplitDropdownActionSheet : SplitDropdownRegular
    } else {
      DropdownComponent = isMobile ? DropdownActionSheet : DropdownRegular
    }

    return (
      <DropdownComponent {...this.props}
        show_action_sheet={this.state.show_action_sheet}
        toggleActionSheet={this.toggleActionSheet}
      />
    )
  }
}

Dropdown.propTypes = {
  split: PropTypes.bool, // pass true for a split button. If true, must pass either href or onClick
  href: PropTypes.string, // href for split button
  onClick: PropTypes.func, // onClick handler for split button
  noCaret: PropTypes.bool, // pass true to not show a caret
  action_sheet_title: PropTypes.oneOfType([ // pass this to show a title displayed for context on action sheet
    PropTypes.string,
    PropTypes.element,
  ]),
  className: PropTypes.string,
  jane_only: PropTypes.bool,
  pullRight: PropTypes.bool,
  disabled: PropTypes.bool,
  options: PropTypes.arrayOf(PropTypes.object).isRequired, // [{}, {}]
  bsSize: PropTypes.oneOf(
    ['large', 'lg', 'small', 'sm', 'xsmall', 'xs']
  ),
  bsStyle: PropTypes.oneOf(
    ["success", "warning", "danger", "info", "default", "primary", "link"]
  ),
}

System:

  System:
    OS: macOS Mojave 10.14.6
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
  Binaries:
    Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
    Yarn: 1.19.2 - /usr/local/bin/yarn
    npm: 6.12.1 - ~/.nvm/versions/node/v8.11.3/bin/npm
  Browsers:
    Chrome: 79.0.3945.117
    Safari: 13.0.4
  npmPackages:
    @storybook/addon-actions: ^5.3.2 => 5.2.5
    @storybook/addon-docs: ^5.3.2 => 5.2.5
    @storybook/addon-knobs: ^5.3.2 => 5.2.5
    @storybook/addon-links: ^5.3.2 => 5.2.5
    @storybook/addons: ^5.3.2 => 5.2.5
    @storybook/react: ^5.3.2 => 5.2.5

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:38 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
jeffcstockcommented, Jan 13, 2020

Thanks for the helpful explanation @shilman, it explained why it was working before and I realized that we actually hadn’t previously added that as a dependency as it had worked without it.

@danilovaz I fixed by adding babel-plugin-react-docgen as a dev dependency, and then adding react-docgen to plugins for the babel-loader in my webpack config (as our project doesn’t use a .babelrc).

2reactions
patricklafrancecommented, Jan 14, 2020

Its’a an option @shilman , I dont like it though.

It shouldn’t have ever work without the proper babel plugin setup and it’s an easy fix for the user.

If we had back the fallback, I fear we might end up with weird issues that might take a lot of our time to figure out what’s happening.

Could we instead update the error message to suggest to configure properly the babel plugin required by the props table?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React eslint error missing in props validation - Stack Overflow
You need to define propTypes as a static getter if you want it inside the class declaration: static get propTypes() { return {...
Read more >
Typechecking With PropTypes - React
To run typechecking on the props for a component, you can assign the special propTypes property: import PropTypes from 'prop-types'; class Greeting extends ......
Read more >
Open Source Notices - Itential Documentation
... acorn-jsx@5.3.2,npm,MIT acorn-walk@6.2.0,npm,MIT acorn-walk@8.2.0,npm,MIT ... babel-plugin-transform-react-remove-prop-types@0.4.24,npm,MIT ...
Read more >
Mastering Props And PropTypes In React - Smashing Magazine
In this snippet, we are passing a prop named posts to a component named PostList . This prop has a value of {postsList}...
Read more >
https://community.dhis2.org/uploads/short-url/lMmW...
resolution: "@babel/helper-split-export-declaration@npm:7.16.7" ... resolution: "@babel/plugin-syntax-class-properties@npm:7.12.13" ... version: 5.3.2.
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