Doubts about react inheritance

I will now write a simple react component that inherits from react.component. As an intern, I see that colleagues in the company will adopt a step-by-step inheritance approach when completing a piece of content, rather than writing a straightforward component as I do.
I"d like to ask all of you. How can we write such a reusable component? what is the idea? What books should I read

on another occasion, a colleague of list, who can delete or add is encapsulated a class and put the actions of adding and deleting in it, but I just added a method directly to the components of react, asking him where to learn this kind of solution

Oct.15,2021

agrees upstairs, react does not recommend inheritance.

clipboard.png

you can read the official documents

https://reactjs.org/docs/comp.

or Chinese documents

https://react.docschina.org/d.


    It is wrong for
  1. to negate inheritance directly regardless of specific scenarios. Although React emphasizes composition rather than inheritance as a side effect component, in many cases, many problems can be solved through inheritance. It mainly depends on what kind of specific scene.
  2. there are many advantages to separate pure business, which lies in the idea of module division, for example, it can be divided into page layer, logic layer, tool layer, configuration layer, and so on. It is difficult for me to say clearly about this kind of thing. I can only say it simply. Take your scenario as an example, adding, deleting, changing and searching independently to make a service, you can test these services without caring about the view layer. You can even have no idea what the view layer is going to do, but simply provide services, that is, transparency, independence, low coupling, high cohesion, decoupling, and so on. Even if you suddenly change the view layer to Vue , it doesn't affect my service layer. Just rebind the view layer. After all, the service layer is pure js .
  3. how to learn? Code quantity , Reading , consider , quantitative change causes qualitative change.

react is not recommended to use inheritance, usually high-level components or combination .

Menu