neptunian / react-photo-gallery

React Photo Gallery
http://neptunian.github.io/react-photo-gallery/
Other
1.97k stars 310 forks source link

Fix for sortable example #169

Open MortalFlesh opened 4 years ago

MortalFlesh commented 4 years ago

Hello, first of all, thanks for this library!

I'm working on sortable gallery, and I need an index inside a Photo component.

In example code for this here . It works fine, but with react-sortable-hoc:^1.10 they

don't spread the keysToOmit parameter in omit util

So the index itself is omitted as well.

I've found this "work-around" or fix for this.

const SortablePhoto = index =>
  SortableElement(item => <Photo {...item} index={index} />);
const SortableGallery = SortableContainer(({ items }) => (
  <Gallery
    photos={items}
    renderImage={props => {
      const IndexedSortablePhoto = SortablePhoto(props.index);

      return <IndexedSortablePhoto {...props} />;
    }}
  />
));

There might be a better way to do it, but for those who struggle with this as me, it could be helpful.

So please, consider to update your example as well.

Thank you :)

skoal2007 commented 3 years ago

Thank you. Save me a lot of time.