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)
答案 0 :(得分:0)
我相信您正在寻找使用react-codemod
的jscodeshift
。
前几天我刚刚完成了这个过程,这是你需要做的事情的简化版本:
jscodeshift
:
npm install -g jscodeshift
react-codemod
存储库:
git clone https://github.com/reactjs/react-codemod.git
react-codemod
的依赖项:
cd ./react-codemod
npm install
cd ../my-project
通过指定转换文件来执行代码转换:
PropTypes
,我们的组件位于/my-project/src
jscodeshift -t ../react-codemod/transforms/React-PropTypes-to-prop-types.js ./src
要包含JSX扩展,请使用extensions
选项:
jscodeshift -t ../react-codemod/transforms/React-PropTypes-to-prop-types.js ./src --extensions js,jsx
如果一切顺利,您应该看到jscodeshift
处理N个文件: