網站首頁 編程語言 正文
最近在做react項目的時候遇到了幾個報錯,這幾個報錯在react項目還算常見,因此記錄下來解決方法。
’type’ is missing in props validation
報錯:type缺少props驗證
解決:
1.查看下propTypes是否寫成大寫了,因為我們引入的時候是大寫的,所以很多小伙伴可能直接復制過來就成大寫了,也會報錯哦
2.新增type: PropTypes.number
import PropTypes from 'prop-types';
const ReportOperate = ({ logId, type }) => {
return <>
<a href='javascript:;' onClick={() => handleJump(record.logId, record.type)} style={{ color: '#1DA57A' }}>查看詳情</a>
<a href={record.filePath} style={{ marginLeft: 20, color: '#1DA57A' }}>下載日志</a>
</>
}
ReportOperate.propTypes = {
logId: PropTypes.number,
type: PropTypes.number,//加上這句就好了
}
export default ReportOperate
throw new Error(‘Cyclic dependency’ + nodeRep)
Error:Cyclic dependency
報錯: Webpack 循環(huán)依賴
解決:
npm i --save-dev html-webpack-plugin@next
Cannot destructure property getFieldDecorator of ‘undefined’ or ‘null’.
報錯: 無法破壞getFieldDecorator屬性undefine或null
解決:
1.是否沒有注入Form.create()
// 無狀態(tài)組件
export default Form.create()(SearchForm)
//有狀態(tài)組件
@Form.create()
Uncaught Error: Invariant Violation: Objects are not valid as a React child (found: object with keys {child}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of Matchs.
報錯原因: 對數組進行map,然后取成了對象
解決:
1.map里面某一項取值是對象
Uncaught TypeError: Cannot read property ‘isSelectOptGroup’ of undefined
報錯原因: const Option = Select.option 引入ant design 的select錯誤
解決:
改成下面的
const { Option } = Select
VM38184:1 Uncaught (in promise) Error: Actions must be plain objects. Use custom middleware for async actions.
報錯原因: 缺少了dispatch
解決:
改成下面的
backend.js:6 ./src/pages/beach/containers/Reward.js
Module not found: Error: Can’t resolve ‘antd/es/descriptions’ in '/Users/chenjiaxin/bull/src/pages/beach/containers’
或者
Module not found: Can’t resolve 'antd/es/affix’
報錯原因:
在項目中使用了antd里面的Descriptions描述列表組件,發(fā)現報了這個錯誤,根本原因就是使用的antd版本里面沒有這個組件,項目中引用的antd版本是3.16.0,而我看的文檔版本已經到了3.24.0了
解決: 將antd 版本更新到最新或者文檔里的版本
Uncaught TypeError: Cannot convert undefined or null to object
報錯原因: 由于undefined和null無法轉成對象,如果用Object.keys等操作的話需要加個對象作為初始值。
解決:
const [firstResponsibility, setFirstResponsibility] = useState({})
Uncaught TypeError: Cannot read property ‘value’ of null
報錯原因: 涉及到React中的合成事件,debounce包裝后的回調函數,是個異步事件,即e.target為null了
The SyntheticEvent is pooled. This means that the SyntheticEvent object will be reused and all properties will be nullified after the event callback has been invoked. This is for performance reasons. As such, you cannot access the event in an asynchronous way.
解決:
//錯誤代碼
<Search
addonBefore={prefixSelector}
style={{ width: 250 }}
allowClear
onChange={debounce(e => {
console.log('e', e)
e.persist()
setSearchValue((e.target || {}).value)
handleChangeParams(searchId, (e.target || {}).value)
}, 1000)}
/>
// 錯誤代碼,可以執(zhí)行,但是還是執(zhí)行多次,沒有起到防抖的效果
<Search
addonBefore={prefixSelector}
style={{ width: 250 }}
allowClear
onChange={e => {
e.persist()
debounce(() => {
setSearchValue((e.target || {}).value)
handleChangeParams(searchId, (e.target || {}).value)
}, 2000)()
}}
/>
// 正確代碼
<Search
addonBefore={prefixSelector}
style={{ width: 250 }}
allowClear
onChange={e => {
e.persist()
handleChangeValue(e)
}}
/>
const handleChangeValue = debounce(e => {
setSearchValue((e.target || {}).value)
handleChangeParams(searchId, (e.target || {}).value)
}, 1000)
vendor.js:1 Uncaught Error: Minified React error #306; visit https://reactjs.org/docs/error-decoder.html?invariant=306&args[]=()&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
報錯原因: 標簽內的onClick事件立刻執(zhí)行導致死循環(huán),加載過多
解決:
// 錯誤代碼
<CommonTabBox onCallBack={setCurTab} />
// 正確代碼
<CommonTabBox onCallBack={val => setCurTab(val)} />
無法使用 JSX,除非提供了 “–jsx” 標志
解決:
在vscode的setting.json中設置
"typescript.tsdk": "node_modules\\typescript\\lib",
無法找到模塊“react/jsx-runtime”的聲明文件。
解決:
npm install -D @types/庫的名字
原文鏈接:https://blog.csdn.net/zn740395858/article/details/92798527
相關推薦
- 2022-04-20 C#實現變量交換、斐波那契數列、質數、回文方法合集_C#教程
- 2023-01-29 Python操作lxml庫實戰(zhàn)之Xpath篇_python
- 2022-09-04 Python?numpy和matlab的幾點差異介紹_python
- 2022-08-18 nginx之queue的具體使用_nginx
- 2022-07-31 如何理解C++指針常量和常量指針_C 語言
- 2022-09-26 折半插入排序算法詳解之C語言版
- 2022-04-11 Maven如果將本地jar包添加到pom中
- 2022-12-04 Flutter組件適配方法實現詳解_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支