Skip to content

How to get component's PropTypes with a CreateReactApp project

Notifications You must be signed in to change notification settings

dibericky/react-get_Component_PropTypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to get component's PropTypes with a CreateReactApp project

1: yarn add axe-prop-types

2: yarn add react-app-rewired

3: In package.json change these lines:

"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",

into these:

"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",

Add at the root of your project (at the same level of package.json) a file named config-overrides.js with this content:

const path = require("path");

module.exports = function override(config, env) {
  return {
    ...config,
    resolve: {
      ...config.resolve,
      alias: {
        ...config.resolve.alias,
        "prop-types$": path.join(__dirname, "node_modules/axe-prop-types")
      }
    }
  };
};

Now you have access to the PropTypes info of the component. Try:

console.log(MyComponent.propTypes)

About

How to get component's PropTypes with a CreateReactApp project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages