1
0
Fork 0
mirror of https://github.com/Alamantus/Lexiconga.git synced 2026-04-26 20:43:15 +02:00
Lexiconga/src/components/display/WordsList.jsx
Robbie Antenesse 43d2d48b27 Add PropTypes verifications to all components
1) to help me when I screw up and 2) to have a clearly laid out but
still useful way of knowing what props a component can accept!
2017-11-15 16:07:42 -07:00

56 lines
1.4 KiB
JavaScript

import Inferno from 'inferno';
import Component from 'inferno-component';
import PropTypes from 'prop-types';
import marked from 'marked';
// npm lazyload-inferno-component uses outdated inferno dependencies, so just using the script.
import LazyLoader from '../../../vendor/LGabAnnell/lazyload-inferno-component/lazyload-component';
import idManager from '../../managers/IDManager';
import { WordDisplay } from './WordDisplay';
const loadAd = (callback, { props, router }) => {
require.ensure([], (require) => {
const component = require("./Ad").Ad;
callback(component);
});
};
export class WordsList extends Component {
constructor (props) {
super(props);
PropTypes.checkPropTypes({
adsEveryXWords: PropTypes.number,
words: PropTypes.array,
updateDisplay: PropTypes.func.isRequired,
}, props, 'prop', 'WordList');
}
render () {
const adsEveryXWords = this.props.adsEveryXWords || 10;
return (
<div className='box'>
{this.props.words
&& this.props.words.map((word, index) => {
return (
<div>
{index % adsEveryXWords == 0
&& <LazyLoader lazyLoad={ loadAd } />
}
<WordDisplay key={ `word_${word.id}` }
word={ word }
updateDisplay={ this.props.updateDisplay } />
</div>
);
})
}
</div>
);
}
}