我試圖使用反應砌體組分:我以前用過的jQuery原來的磚石插件https://github.com/eiriklv/react-masonry-component遇到問題使用反應砌體組分
但我完全新的ReactJs和它的代碼結構。我已經添加了組件文檔中給出的示例代碼,但不知道如何使其工作。我想弄清楚如何將元素添加到砌體網格以及如何將此代碼重構爲ES6。
import React, { PropTypes } from 'react';
import styles from './Works.css';
import withStyles from '../../../../decorators/withStyles';
import Button from '../../../Button';
var Masonry = require('react-masonry-component')(React);
var masonryOptions = {
transitionDuration: 0
};
@withStyles(styles)
class Works extends React.Component {
render() {
var childElements = this.props.elements.map(function(element){
return (
<li className="WorkItem">
<img src={element.src} />
</li>
);
});
return (
<div className="Works">
<h3>Works</h3>
<Masonry
className={'WorkList'}
elementType={'ul'}
options={masonryOptions}
disableImagesLoaded={false}>
{childElements}
</Masonry>
</div>
);
}
}
export default Works;
我得到的錯誤:
TypeError: Cannot call method 'map' of undefined
at Works.render (/Users/hilarl/Desktop/client/build/webpack:/src/components/ProfilePage/Layout/Works/Works.js:16:45)
at [object Object].ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactCompositeComponent.js:546:34)
at [object Object].ReactCompositeComponentMixin._renderValidatedComponent (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactCompositeComponent.js:566:32)
at [object Object].wrapper [as _renderValidatedComponent] (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactPerf.js:66:21)
at [object Object].ReactCompositeComponentMixin.mountComponent (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactCompositeComponent.js:181:32)
at [object Object].wrapper [as mountComponent] (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactPerf.js:66:21)
at Object.ReactReconciler.mountComponent (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactReconciler.js:37:35)
at [object Object].ReactCompositeComponentMixin.mountComponent (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactCompositeComponent.js:185:34)
at [object Object].wrapper [as mountComponent] (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactPerf.js:66:21)
at Object.ReactReconciler.mountComponent (/Users/hilarl/Desktop/client/node_modules/react/lib/ReactReconciler.js:37:35)
我使用的陣營0.14.0-β3
任何幫助,非常感謝。非常感謝。