Why not use React.Component.prototype.$store = store in React like Vue

Global libraries are often added to VUE.prototype in VUE. Why few people use them in react? I think this is much more convenient than using context.

Mar.30,2021

first of all, you can write this in react. For example:

React.Component.prototype.$store = $store;

is available, but this is not common! Why? Listen to me blow for you.

react is more pure , functional .

mounting your method to prototype is a very impure operation.

you can take a look at redux, the popular data management library in react ecology, which is implemented through react-redux with higher-order functions with the help of context.
you can see a lot of these operations in react , in contrast, you will see that there are a lot of operations in vue that attach objects and methods to prototype.

how many HOC models have you seen in vue?


first of all, I don't know how to react, after watching it three or four times. I find it difficult to get started, or maybe it's because of my skill. If you look at what you said, ah, I think it is mainly because of the writing method. The functional programming of react is basically written as class an extends b., class Point = Point.prototype.constructor.. It's pure nonsense, and I know if it's right, I also wrote it to ask other great gods whether I can add things to


Why not import? this addition will make others think that it is brought with it, but a refactoring or modification will wonder why


react does not recommend extending


key how to use it

Menu