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

WrappedComponent.defaultProps is missing in mapStateToProps #111

Closed
wenbing opened this issue Sep 16, 2015 · 4 comments
Closed

WrappedComponent.defaultProps is missing in mapStateToProps #111

wenbing opened this issue Sep 16, 2015 · 4 comments

Comments

@wenbing
Copy link

wenbing commented Sep 16, 2015

class Foo extends React.Component {
  render() {
    return <div>this.props.bar</div>
  }
}

Foo.defaultProps = {
  bar: 'baz'
}

module.exports = connect(function mapStateToProps(state, props) {
  console.log(props.bar) // undefined 
})(Foo)
@gaearon
Copy link
Contributor

gaearon commented Sep 16, 2015

connect() returns a new component. If you'd like defaultProps to be present on it, you need to put defaultProps on it:

class Foo extends React.Component {
  render() {
    return <div>this.props.bar</div>
  }
}

Foo = connect(function mapStateToProps(state, props) {
  console.log(props.bar) 
})(Foo)

Foo.defaultProps = {
  bar: 'baz'
}

module.exports = Foo;

@gaearon gaearon closed this as completed Sep 16, 2015
@arcanis
Copy link

arcanis commented Aug 1, 2016

@gaearon shouldn't this be handled by the library? It doesn't feel very intuitive this way (especially when using decorators and static properties), and doing the opposite (by requiring to manually delete the defaultProps from the wrapper element should the forwarding be undesirable) seems a saner default behaviour.

@markerikson
Copy link
Contributor

No, the current behavior makes sense based on both the tooling, the language syntax, and the conceptual idea of defining "original" components vs defining wrappers for them.

@reduxjs reduxjs deleted a comment from kusmierz Jun 20, 2017
@WalidKurchied

This comment has been minimized.

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

5 participants