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

后端 未结 30 955
無奈伤痛
無奈伤痛 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:48

    This is a general issue, and doesn't appear in a single case. But, the common problem in all the cases is that you forget to import a specific component (doesn't matter if it's either from a library that you installed or a custom made component that you created):

    import {SomeClass} from 'some-library'

    When you use it later, without importing it, the compiler thinks it's a function. Therefore, it breaks. This is a common example:

    imports

    ...code...

    and then somewhere inside your code

    If you forgot to import the component then the compiler will not complain like it does for other imports, but will break when it reaches your code.

提交回复
热议问题