How to get an audio element?

Using React, I want to get an audio element.

var AudioPlayer = React.createClass({ componentDidMount: function () { console.info('Audio: component did mount'); var audio = React.findDOMNode('audio'); console.info('audio', audio); }, render : function() { return ( <audio src="/static/music/foo.mp3" controls /> ); } }); 

But I get an error all the time:

Error: Invariant violation: the element is neither ReactComponent nor DOMNode (keys: 0,1,2,3,4)

Undoubtedly, are React classes lowered components?

+5
source share
1 answer

It works using component references:

 var AudioPlayer = React.createClass({ componentDidMount: function () { console.info('[AudioPlayer] componentDidMount...'); this.props.el = React.findDOMNode(this.refs.audio_tag); console.info('audio prop set', this.props.el); }, render: function() { console.info('[AudioPlayer] render...'); return ( <audio ref="audio_tag" src="/static/music/foo.mp3" controls autoplay="true"/> ); } }); 
+6
source

All Articles