jeudi 26 mars 2015

Video displayed in ReactJS component not updating


I'm new to ReactJS (0.13.1), and I've created a component in my app to display HTML5 video.


It seems to work perfectly but only for the first selection. The video that is actually displayed and playing in the page doesn't change when you switch from one video to another (when this.props.video changes).


I can see the <source src='blah.mp4' /> elements update in the Chrome inspector but the actually rendered video in the page doesn't change and keeps playing if it was already. Same thing happens in Safari & Firefox. All the other elements update appropriately as well.


Any ideas?


Anyway my component below:



(function(){
var React = require('react');

var VideoView = React.createClass({

render: function(){
var video = this.props.video;
var title = video.title === ''? video.id : video.title;

var sourceNodes = video.media.map(function(media){
media = 'content/'+media;
return ( <source src={media} /> )
});
var downloadNodes = video.media.map(function(media){
var ext = media.split('.').slice(-1)[0].toUpperCase();
media = 'content/'+media;
return (<li><a className="greybutton" href={media}>{ext}</a></li>)
});

return (

<div className="video-container">
<video title={title} controls width="100%">
{sourceNodes}
</video>
<h3 className="video-title">{title}</h3>
<p>{video.description}</p>
<div className="linkbox">
<span>Downloads:</span>
<ul className="downloadlinks">
{downloadNodes}
</ul>
</div>
</div>

)
}
});
module.exports = VideoView;
})();




Aucun commentaire:

Enregistrer un commentaire