clauderic / react-sortable-hoc

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️
https://clauderic.github.io/react-sortable-hoc/
MIT License
10.75k stars 977 forks source link

Make it easier to use #760

Open Felix-Franz opened 3 years ago

Felix-Franz commented 3 years ago

You can use the lib much easier if you would include this:

import {SortableContainer, SortableElement, SortableHandle} from "react-sortable-hoc";

const component = ({children}: {children: JSX.Element}) => children;

export const SortableItem = SortableElement(component);
export const SortableList = SortableContainer(component);
export const SortHandle = SortableHandle(component);

Usage:

<SortableList>
    <ul>
    {this.state.elementForList.map((c, i) =>
        <SortableItem key={i} index={i}>
            <li>{c}</li>
        </SortableItem>
    </ul>
    )}
</SortableList>
thepuzzlemaster commented 3 years ago

Thanks for this. I created a sortableUtils.ts which exports these consts, and this does make it sooooo much more pleasant to use.