React 开发常见报错解决方法


1. 使用 redux 的异步 action 时浏览器报错:

Error: Actions must be plain objects. Use custom middleware for async actions.

【原因】没有添加 thunk 中间件

【解决方法】在入口文件中添加中间件,并在 createStore 时进行注册:

import thunkMiddleware from 'redux-thunk'
const createStoreWithMiddleware = applyMiddleware(loggerMiddleware, thunkMiddleware)(createStore)

 

2. ant design pro 开启 eslint 后出现大量 warning:

Line 1:  Definition for rule 'jsx-a11y/href-no-hash' was not    jsx-a11y/href-no-hash

【原因】airbnb 的插件 jsx-a11y 暂时不能使用v6版本。

【解决方案】降低 eslint-plugin-jsx-a11y 版本为 5.1.0

npm install eslint-plugin-jsx-a11y@5.1.0 --save-dev

【注】

1. 在 antd pro 上提 issure,给的回复是 update eslint,尝试过,无效。

2. google 上的解决方法是在 eslint 文件中添加规则:'jsx-a11y/href-no-hash': 'off' ,尝试过,无效。 

3. 参考资料:eslint 结合webpack 在React环境下的使用

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM