eiriklv / react-masonry-component

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

How to append/prepend items without re-rendering the whole grid? #29

Closed empz closed 8 years ago

empz commented 8 years ago

In my React application I've set a timer that polls for new posts from a certan API. Whenever a new post is fetched, the component that holds the Masonry component receives the updated array of posts causing the render() method to trigger. This causes the whole grid to be re-rendered (all the items do the animation, instead of just the new ones).

In the old project I used to do that the masonry docs says:

$grid.prepend( $items )
// add and lay out newly prepended items
    .masonry( 'prepended', $items );

How to achieve such behavior with react and react-masonry-component?

I'm new to React so maybe this is not related specifically to your component. I'm sorry if that's the case.

empz commented 8 years ago

Nevermind. I was doing things wrong.

Works like a charm!