React PropTypes vs. Flow

前端 未结 4 1975
既然无缘
既然无缘 2021-01-30 04:52

PropTypes and Flow cover similar things but are using different approaches. PropTypes can give you warnings during runtime, which can be helpful to quickly find malformed respon

4条回答
  •  抹茶落季
    2021-01-30 05:39

    Try declaring the type of props using only Flow. Specify an incorrect type, such as number instead of string. You'll see that this will be flagged in code that uses the component within your Flow-aware editor. However, this will not cause any tests to fail and your app will still work.

    Now add use of React PropTypes with an incorrect type. This WILL cause tests to fail and be flagged in the browser console when the app is run.

    Based on this, it seems that even if Flow is being used, PropTypes should also be specified.

提交回复
热议问题