React.js and Isotope.js

前端 未结 8 1768

I\'m checking out React.js and trying to figure out how this library can work together with Isotope.js. The documentation of React says that it plays nicely with other libra

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 03:44

    Here's a working version with Masonry, you should find it easy enough to port to Isotope (or use Masonry :)) http://jsfiddle.net/emy7x0dc/1/.

    Here's the crux of the code that makes it work (and allow React to do its job).

    var Grid = React.createClass({
        displayName: 'Grid',
    
        getInitialState: function(){
            return {
                masonry: null
            }
        },
    
        // Wrapper to layout child elements passed in
        render: function () {
            var children = this.props.children;
            return (
                
    {children}
    ); }, // When the DOM is rendered, let Masonry know what's changed componentDidUpdate: function() { if(this.state.masonry) { this.state.masonry.reloadItems(); this.state.masonry.layout(); } }, // Set up Masonry componentDidMount: function() { var container = this.getDOMNode(); if(!this.state.masonry) { this.setState({ masonry: new Masonry( container ) }); } else { this.state.masonry.reloadItems(); } } });

提交回复
热议问题