I have a component-component render on page load. The content includes a lot of multimedia materials, which I want to lazy to download only when the content is on the screen, and then unloads it when it is missing. More content loads as the user scrolls.
I use a combination of methods to handle lazy downloadable frames, videos, and images, and it works great outside of the content passed through React. Mostly custom jQuery and the "Lazy Load Anything " library .
My main problem is that I cannot get my lazy boot function to run content just placed in dom. It works when the user resizes / scrolls (I have events for this that fire accordingly). How to make it run when content is available?
I tried to launch it from componentDidMount component, but this does not seem to work as the content has not yet been placed in the DOM.
I suppose I can just check the contents every n seconds, but I would like to avoid this for performance reasons.
Here is my simplified code:
var EntriesList = React.createClass({
render: function() {
var entries = this.props.items.map(function(entry) {
return (
<div className="entry list-group-item" key={entry.id}>
<img src="1px.gif" className="lazy" datasource="/path/to/original" />
<video poster="1px.gif" data-poster-orig="/path/to/original" preload="none">{entry.sources}</video>
</div>
);
});
return(<div>{entries}</div>);
}
});
var App = React.createClass({
componentDidMount: function() {
$.get('/path/to/json', function(data) {
this.setState({entryItems: data.entries});
}.bind(this));
myLazyLoad();
},
getInitialState: function() {
return ({
entryItems: []
});
},
render: function() {
return (<div><EntriesList items={this.state.entryItems} /></div>);
}
});
React.render(<App />, document.getElementById('entries'));
source
share