2

I've looked at other similar questions but can't seem to find an answer...

I'm getting error:

Warning: Failed prop type: The prop height is marked as required in AudioPlayer, but its value is undefined.

When trying the following code:

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
};

The code still functions as expected but gives the error mentioned above.

Should I be checking prop types differently?

4
  • can you show how are you rendering AudioPlayer ? Commented Sep 9, 2017 at 6:42
  • What do you not understand about the error? Commented Sep 9, 2017 at 6:43
  • 1
    You do not need AudioPlayer.propTypes = { height: PropTypes.number.isRequired };. it is needed in Audio component. Commented Sep 9, 2017 at 6:48
  • Thanks guys, oversight on my part Commented Sep 9, 2017 at 6:52

1 Answer 1

2

From what I see in your question description, uou have no dependency of prop height in the AudioPlayer component. You would rather want it in the Audio Component and hence you need to specify Proptype for the Audio component

so In the Audio component file add and remove from AudioPlayer component file.

Audio.propTypes = {
    height: PropTypes.number.isRequired
};
Sign up to request clarification or add additional context in comments.

1 Comment

Argh - thanks, too much staring - will accept when I can, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.