How to override a parent class method in React?

后端 未结 4 618
一个人的身影
一个人的身影 2021-01-05 03:07

I\'m extending a base class and overriding a method in the base class. But when I call it, it calls the super class version. How do I override the method?

           


        
4条回答
  •  梦谈多话
    2021-01-05 03:21

    Please note that this answer proposes different approach:

    I wonder why you should do this in the first place, my point is that directly coupling two react components is not a right way to implement re-usability in React.

    If you are trying to have multiple child components which extends one parent, What I would do is, to have child components and a higher-order component and then implement common functionality with Composition. This way you can skip those methods, which you were trying to override and so everything would stay clear.

提交回复
热议问题