react-sortable-hoc optimisations and docs help
See original GitHub issueI currently have this version of a drag and drop sortable list working with react-virtuoso. My goal is to get this documented either here or on react-sortable-hoc docs.
If i could get some help on if there are better ways to get the index in ItemContainer, and help on whether using ItemContainer and ListContainer are even the best options to accomplish this: Then i will go to react-sortable-hoc and make a PR to add react-virtuoso docs to the ones they have already for react-virtualized, react-infinite, and tiny-react-virtual-list
Alternatively this could be added to the docs in this repo too on how to use drag and drop in the virtual list
import React, { useCallback } from 'react';
import { Virtuoso } from 'react-virtuoso';
import { sortableContainer, sortableElement } from 'react-sortable-hoc';
const ItemContainerSortable = sortableElement(
props => <div {...props} />
);
const ItemContainer = props => {
const {
['data-index']: index
// I dont know if theres a better way to do this
// but ItemContainerSortable requires an index prop to work
} = props;
return <ItemContainerSortable index={index} {...props} />;
};
const ListContainerSortable = sortableContainer(
({ listRef, children, className, style }) => (
<div
ref={listRef}
className={className}
style={style}
>
{children}
</div>
)
);
const List = props => {
const {
onSortEnd
} = props;
const ListContainer = useCallback(
(props) => (
<ListContainerSortable
{...props}
onSortEnd={onSortEnd}
/>
),
[onSortEnd]
);
return (
<Virtuoso
{...props}
ItemContainer={ItemContainer}
ListContainer={ListContainer}
/>
)
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
react-sortable-hoc - npm
React Sortable HOC supports keyboard sorting out of the box. To enable it, make sure your SortableElement or SortableHandle is focusable. This ...
Read more >clauderic/react-sortable-hoc - Gitter
I'm using react-sortable-hoc and antd Table to make an editable cell table. ... Does react-sortable-hoc support table merging, cell dragging and sorting?
Read more >React Sortable Higher-order Components
Set of higher-order components to turn any list into a sortable, touch-friendly, animated list.
Read more >Higher Order Components to Turn any List into A Dynamically ...
React Sortable HOC supports keyboard sorting out of the box. To enable it, make sure your SortableElement or SortableHandle is focusable. This can...
Read more >Drag and Drop in React with 'react-sortable-hoc' - Medium
It is important to note that 'react-sortable-hoc' requires that your components follow some structural rules. You must use two components from the package;...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The example is deployed to the site.
@itrare post your implementation and point towards the problems you are facing.