1.写一个组件,实现如下图效果
我是用的是antd UI框架,该组件是被父组件所在的form表单代码块包裹的,如下图:
组件内代码如下:
执行的时候报如下错误:
但这个getFieldDecorator我是有导入过来的
**解决办法:**最后发现是在父组件里没有props传递过来
2.实现一个如下图输入验证码发送短信的功能组件
功能没有问题,但会报如下错误,我是使用antd UI框架,提交是使用框架的form表单提交的,报错如下:
Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
代码如下图:
**解决办法:**是因为我是用<Form.Item></Form.Item>
包裹了该组件,去掉<Form.Item></Form.Item>
标签,就不会出现上面报错问题
3.出现如下错误:
Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
貌似防止内存泄漏的警告
4.出现如下错误:
Uncaught Invariant Violation: Calling PropTypes validators directly is not supported by the
prop-typespackage. Use
PropTypes.checkPropTypes() to call them.
**解决方法:**我的react和react-dom版本是15.0.0,升级到最新版本15.3.0+就可以了。详细内容可以点击这里
5.不使用脚手架纯手动构建一个react项目,结果在创建/src/index.js这个入口文件时一直报格式错误
如下图: