失败的道具类型:没有指定所需的道具
React Redux Failed prop type: Required prop was not specified
我遇到了一些问题,失败的道具类型试图学习Redux与反应。事情是我想创建一个带有标题和一些文本的注释,但由于Failed prop类型只有标题将显示。
警告:
warning.js:36 Warning: Failed prop type: Required prop `notes[0].text` was not specified in `NoteList`.
in NoteList (created by Connect(NoteList))
in Connect(NoteList) (created by App)
in div (created by App)
in App
in Provider
warning.js:36 Warning: Failed prop type: Required prop `text` was not specified in `Note`.
in Note (created by NoteList)
in NoteList (created by Connect(NoteList))
in Connect(NoteList) (created by App)
in div (created by App)
in App
in Provider
ListNotes.js:
import { connect } from 'react-redux'
import NotesList from '../components/NotesList'
const mapStateToProps = (state) => {
return {
notes: state.notes
}
}
const ListNotes = connect(
mapStateToProps
)(NotesList)
export default ListNotes
NotesList.js:
import React, { PropTypes } from 'react'
import Note from './Note'
const NoteList = ({ notes }) => {
return (
<ul>
{notes.map(note =>
<note
key={note.id}
{...note}
/>
)}
</ul>
)
}
NoteList.propTypes = {
notes: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
title: PropTypes.string.isRequired,
text: PropTypes.string.isRequired
}).isRequired).isRequired
}
export default NoteList
Note.js:
import React, { PropTypes } from 'react'
const Note = ({title, text}) => {
return (
<li>
<h1>{title}</h1>
<p>{text}</p>
</li>
)
}
Note.propTypes = {
title: PropTypes.string.isRequired,
text: PropTypes.string.isRequired
}
export default Note
检查state.notes
中的内容。你可以记录它,或者在某处设置一个断点,然后使用浏览器的调试器。
似乎该数组中的对象没有text
属性或设置为undefined
或null
。您可能在应该设置该值的地方出现了错别字。
如果你能看到标题,那么其他一切似乎都井然有序。
相关文章:
- JavaScript严格类型检查失败
- 警告:失败的propType:类型为“array”的无效prop应为React的“object”
- JS:执行'失败;getComputedStyle'在'窗口':参数的类型不是'
- 谷歌地图API多段线创建失败;未捕获类型错误:数字不是函数;
- 1.js:23未捕获类型错误:执行'失败;appendChild'在'节点':参数1不是
- JQuery 验证输入类型文件在服务器端失败
- 解析失败,出现: 类型错误: 无法读取未定义的属性“成功”
- React 组件流类型检查中的可选函数属性失败
- 当开机自检失败时,调用哪种类型的 AJAX 事件
- 带有外部依赖项的Jasmine单元测试指令失败,类型错误:'[object对象]'
- Angular Formly自定义类型控制器在部署时失败
- 为什么JQuery NOT选择器在类型提交时失败,但在类型按钮上有效
- 警告:失败的道具类型:在“窗格”中未指定所需的道具“子项”.检查“首次时间选项卡”的呈现方法
- 未捕获类型错误:执行失败'readAsBinaryString'on 'FileReader
- 失败的道具类型:没有指定所需的道具
- Fabrics.js - loadFromJSON()在JSON包含类型'形状'的项目时失败
- 为什么第n种类型的检测只在Firefox中失败?
- 未捕获的类型错误:执行失败'on 'FileReader':参数1不是'Blob'
- “.import"语句(用于在JS中导入Qml类型)失败,出现语法错误
- JS-拖动;删除文件和获取文件类型失败