react v15 PropTypes and CreateClass

时间:2017-04-24 17:28:48

标签: reactjs react-proptypes

As I'm using PropTypes from the react.js library and CreateClass i'm a bit worried that those 2 are deprecated on the next major version of react.js.

After updating to react v15 I'm getting the warnings about it. I've read that there is a script that can auto refactor it (extracting PropTypes to the new library) but can't find it now.

anyone tried that script and can share his / her experience with it? (and know where can i find it of course)

And how safe is it to keep my current syntax? what are the downsides beside losing the ability to migrate to v16 (fiber)

1 个答案:

答案 0 :(得分:0)

我相信您正在寻找使用react-codemodjscodeshift

前几天我刚刚完成了这个过程,这是你需要做的事情的简化版本:

  1. 全球安装jscodeshift
    • npm install -g jscodeshift
  2. 克隆react-codemod存储库:
    • git clone https://github.com/reactjs/react-codemod.git
  3. 安装react-codemod的依赖项:
    • cd ./react-codemod
    • npm install
  4. 将目录更改为您的项目:
    • cd ../my-project
  5. 通过指定转换文件来执行代码转换:

    • 我们要修复PropTypes,我们的组件位于/my-project/src
      • jscodeshift -t ../react-codemod/transforms/React-PropTypes-to-prop-types.js ./src
  6. 要包含JSX扩展,请使用extensions选项:

    jscodeshift -t ../react-codemod/transforms/React-PropTypes-to-prop-types.js ./src --extensions js,jsx

  7. 如果一切顺利,您应该看到jscodeshift处理N个文件:

    enter image description here