eiriklv / react-masonry-component

A React.js component for using @desandro's Masonry
MIT License
1.44k stars 145 forks source link

Need help with Append #102

Closed azsherif closed 6 years ago

azsherif commented 6 years ago

Hi,

I request you help in appending new set of items by accessing the Masonry Instance.

My Main Component

<Masonry className={'row'} // default ''

  elementType={'div'} // default 'div'

  options={masonryOptions} // default {}

  disableImagesLoaded={false} // default false

  updateOnEachImageLoad={false} // default false and works only if disableImagesLoaded is false

  ref={function(c) {
        this.masonry = this.masonry || c.masonry;
      }.bind(this)}>
        {this.renderItems()}
      </Masonry>
    );
  }
}

under component did mount i did the following

console.log(this.masonry);
//items is new array of items
this.masonry.append(items).masonry('appended',items);

I am not sure if i am doing it right, Please help me with an example

afram commented 6 years ago

@DeathDealerr

You don't use the underlying Masonry object to add items. You need to add items to the object returned from calling this.renderItems() if that makes sense.

Be sure to do this in the React way though. Use setState if you aren't using Redux - otherwise do this in the 'redux' way.

azsherif commented 6 years ago

@afram ,

Thank you for the help.