question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-sortable-hoc optimisations and docs help

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
petyosicommented, May 8, 2020
0reactions
petyosicommented, Jun 21, 2021

@itrare post your implementation and point towards the problems you are facing.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found