1.0.3 • Published 10 months ago

find-react-legacy-context-usages v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Find React Legacy Context Usages

The title says it. See sample reports in here and here.

Usage

npx find-react-legacy-context-usages \
    "./src/**/*.{js,jsx,ts,tsx}" \
    --root="./src" \
    --report-file="./legacy-context-usages-report.json"

Options

--root: Root folder for sources where .babelrc exists.

--report-file: Report file output path

Important: Don't forget the double-quotes in path glob.

What's supported?

// ClassProperty
class SampleComponent extends React.Component {
  static contextTypes = {
    darkMode: PropTypes.bool.isRequired,
    isLoggedIn: PropTypes.bool.isRequired,
  };

  static childContextTypes = {
    darkMode: PropTypes.bool.isRequired,
    isLoggedIn: PropTypes.bool.isRequired,
  };
}

// AssignmentExpression
function SampleFunctionalComponent() {}

SampleFunctionalComponent.contextTypes = {
  darkMode: PropTypes.bool.isRequired,
  isLoggedIn: PropTypes.bool.isRequired,
};

SampleFunctionalComponent.childContextTypes = {
  darkMode: PropTypes.bool.isRequired,
  isLoggedIn: PropTypes.bool.isRequired,
};

What's not supported?

class SampleComponent extends React.Component {
  static contextTypes = someStupidVariableContainingTheContextTypes;
  static childContextTypes = someStupidVariableContainingTheChildContextTypes;
}