Why doesn't React.js have stateTypes?

Real components conceptually separate their data into requisites, immutable data passed from their parent element, and state, mutable data supported locally. The only thing I like about React is its support for limited type checking in the form of propTypes . Why is there no such concept of state (e.g. stateTypes)?

+7
reactjs
source share
1 answer

Using the so-called stateTypes will not do you much good.

According to the official React website about propTypes:

As your application grows, it is helpful to ensure that your components are used properly.

It is important to remember that propTypes checks to see if you passed the correct data to the current element in the place where you are executing this component . You can reuse a component as many times as you like, so it can easily happen that you forgot to pass the appropriate properties to it.

Therefore, checking the data transferred from "another source" is more important and more profitable than checking the data that you use when you write the component itself. If you could work with information from a state somewhere else that you cannot, it would be useful to use.

In any case, this is just a practical tool for easier development, which should be disabled in the production environment.

Conclusion: maybe this question is a little based on opinions. I believe that using stateTypes would not help if you declared your state in the constructor (ES2015) or getInitialState and just a few lines below the exact same information, only in the form of stateTypes.

+6
source share

All Articles