Getting “Cannot call a class as a function” in my React Project

后端 未结 30 719
無奈伤痛
無奈伤痛 2020-12-07 16:34

I\'m trying to add a React map component to my project but run into an error. I\'m using Fullstack React\'s blog post as a reference. I tracked down where the error gets thr

相关标签:
30条回答
  • 2020-12-07 16:37
    Post.proptypes = {
    
    }
    

    to

    Post.propTypes = {
    
    }
    

    someone should comment on how to monitor such error in a very precise way.

    0 讨论(0)
  • 2020-12-07 16:37

    Another report here: It didn't work as I exported:

    export default compose(
      injectIntl,
      connect(mapStateToProps)(Onboarding)
    );
    

    instead of

    export default compose(
      injectIntl,
      connect(mapStateToProps)
    )(Onboarding);
    

    Note the position of the brackets. Both are correct and won't get caught by either a linter or prettier or something similar. Took me a while to track it down.

    0 讨论(0)
  • 2020-12-07 16:38

    I experienced the same issue, it occurred because my ES6 component class was not extending React.Component.

    0 讨论(0)
  • 2020-12-07 16:39

    I had it when I did so :

    function foo() (...) export default foo
    

    correctly:

    export default  () =>(...);
    

    or

    const foo = ...
    export default foo
    
    0 讨论(0)
  • 2020-12-07 16:40

    For me it was because I forgot to use the new keyword when setting up Animated state.

    eg:

    fadeAnim: Animated.Value(0),

    to

    fadeAnim: new Animated.Value(0),

    would fix it.

    0 讨论(0)
  • 2020-12-07 16:41

    Try stopping you HMR and hit npm start again to rebuild you project.
    This ,made the error to disappear, don't know why.

    0 讨论(0)
提交回复
热议问题