ReactJS失败的道具类型为';未定义';价值
我看过其他类似的问题,但似乎找不到答案 我得到一个错误: 警告:失败的道具类型:道具ReactJS失败的道具类型为';未定义';价值,reactjs,validation,types,Reactjs,Validation,Types,我看过其他类似的问题,但似乎找不到答案 我得到一个错误: 警告:失败的道具类型:道具高度在音频播放器中按要求标记,但其值为未定义 尝试以下代码时: import React, { Component } from "react"; import { Row, Col } from "react-bootstrap"; import Audio from "react-audioplayer"; import "./../../Assets/Css/AudioPlayer.css"; import
高度
在音频播放器
中按要求标记,但其值为未定义
尝试以下代码时:
import React, { Component } from "react";
import { Row, Col } from "react-bootstrap";
import Audio from "react-audioplayer";
import "./../../Assets/Css/AudioPlayer.css";
import PropTypes from "prop-types";
export default class AudioPlayer extends Component {
render(props) {
const playlist = this.props.playlist;
const AudioStyles = {
width: "99%",
margin: "1% 0"
};
const AudioProps = {
height: 600,
style: AudioStyles,
playlist: playlist,
fullPlayer: true
};
return (
<Row>
<Col xs={12}>
<Audio {...AudioProps} />
</Col>
</Row>
);
}
}
AudioPlayer.propTypes = {
height: PropTypes.number.isRequired
};
import React,{Component}来自“React”;
从“react bootstrap”导入{Row,Col};
从“react audioplayer”导入音频;
导入“/。/../Assets/Css/AudioPlayer.Css”;
从“道具类型”导入道具类型;
导出默认类AudioPlayer扩展组件{
渲染(道具){
const playlist=this.props.playlist;
常量音频样式={
宽度:“99%”,
保证金:“1%0”
};
const AudioProps={
身高:600,
风格:音频风格,
播放列表:播放列表,
fullPlayer:是的
};
返回(
);
}
}
AudioPlayer.propTypes={
高度:PropTypes.number.isRequired
};
代码仍按预期运行,但给出了上述错误
我是否应该以不同的方式检查道具类型?从我在您的问题描述中看到的情况来看,uou在
AudioPlayer
组件中不依赖于道具高度。您更希望它位于音频
组件中,因此需要为音频组件指定Proptype
因此,在音频组件文件中,从AudioPlayer
组件文件中添加和删除
Audio.propTypes = {
height: PropTypes.number.isRequired
};
您能否演示如何呈现AudioPlayer
?您不了解错误的哪些方面?您不需要AudioPlayer.propTypes={height:propTypes.number.isRequired}代码>。这是音频组件中所需要的。谢谢各位,我的派对上的疏忽。谢谢,太多的凝视。我会在可以的时候接受的,谢谢!