How to prevent building app if component prop types are invalid?

后端 未结 3 1926
忘了有多久
忘了有多久 2021-02-19 06:08

Here is a example for PropTypes:

import PropTypes from \'prop-types\';

class Greeting extends React.Component {
  render() {
    return (
      

Hello,

3条回答
  •  孤街浪徒
    2021-02-19 06:53

    My personal recommendation is using a static code analysis tool as Aluan Haddad mentioned.

    If you don't want to use a static code analysis tool, you could try to make the code fail on tests using a tool like https://github.com/esphen/jest-prop-type-error. But this implies you should have tests covering the integration between different components completely.

    I would not consider this as a final solution for this problem but could be helpful as a temporary solution for large codebases while migrating to a static code analysis tool.

提交回复
热议问题