eiriklv / react-masonry-component

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

Is there any way to sort the order of elements using this component? #19

Closed pvijeh closed 8 years ago

afram commented 8 years ago

react-masonry-component does not sort it's contents, you have to provide sorted child elements.

Here is a hypothetical example where we put some child elements in descending order. I've left out any non essential details like class names etc.

For this example, props.someElementsArray contains items that are strings, eg:

["foo", "bar", "baz"]
React.createClass({
    render: function() {
        var children = this.props.someElementsArray
            .sort()
            .reverse()
            .map(function(child) {
                return <div>{child}</div>
            });

        return (
            <Masonry>{children}</Masonry>
        );
    }
});

The above code will render something like

<div>
    <div>foo</div>
    <div>baz</div>
    <div>bar</div>
</div>
afram commented 8 years ago

I'm going to close this ticket due to inactivity. Please reopen if you would like to discuss further