Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#125 introduce bug with decorators #130

Open
iam4x opened this issue Mar 8, 2016 · 1 comment
Open

#125 introduce bug with decorators #130

iam4x opened this issue Mar 8, 2016 · 1 comment

Comments

@iam4x
Copy link

iam4x commented Mar 8, 2016

function foobar(DecoratedComponent) {
  return class Parent extends Component {

   state = { isActive: true } 

    render() {
      const { isActive }  = this.state; 
      return <DecoratedComponent isActive={ isActive } />; 
    }

  }
}

@foobar()
class Child {
  props: { isActive: boolean; };

  render() {
    ....
  }
}

In this case, propTypes will be applied to Wrapper instead of Parent it will log in dev-console:

Warning: Failed propType: Invalid prop `isActive` supplied to `Parent`.

Expected:
bool

Got:
void

My .babelrc for help:

{
  "presets": ["save"],
  "plugins": [],
  "env": {
    "browser": {
      "plugins": [
        "typecheck",
        ["react-transform", {
          "transforms": [
            {
              "transform": "react-transform-hmr",
              "imports": [ "react" ],
              "locals": [ "module" ]
            },
            {
              "transform": "react-transform-catch-errors",
              "imports": [ "react", "redbox-react" ]
            }
          ]
        }]
      ]
    },
    "production": {
      "plugins": ["react-remove-prop-types"]
    }
  }
}

My workaround for now, which is painful is to call the decorator as a function in the export.

@ntkoopman
Copy link
Collaborator

Yes, the propTypes are assigned to the wrong class in this case. I have a fix ready, but it still needs to be tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants