TopGit theo dõi SortableJS/react-sortablejs trên GitHub trong nhóm Frontend, đã đạt 2.2k sao. React bindings for SortableJS
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
- Shopping List: # list of items / sortable. This represents `react-sortablejs`
- eggs # list item. These are all the items in the list and are what you move around.
- bread # list item
- milk # list item
These are all default DOM attributes. Nothing special here.
list
The same as state in const [ state, setState] = useState([{ id: 1}, {id: 2}])
state must be an array of items, with each item being an object that has the following shape:
/** The unique id associated with your item. It's recommended this is the same as the key prop for your list item. */
id: string | number;
/** When true, the item is selected using MultiDrag */
selected?: boolean;
/** When true, the item is deemed "chosen", which basically just a mousedown event. */
chosen?: boolean;
/** When true, it will not be possible to pick this item up in the list. */
filtered?: boolean;
[property: string]: any;
setList
The same as setState in const [ state, setState] = useState([{ id: 1}, {id: 2}])
clone
If you're using {group: { name: 'groupName', pull: 'clone'}}, this means you're in 'clone' mode. You should provide a function for this.
Check out the source code of the clone example for more information. I'll write it here soon.
tag
ReactSortable is a div element by default. This can be changed to be any HTML element (for example ul, ol)
or can be a React component.
This value, be it the component or the HTML element, should be passed down under props.tag.
Let's explore both here.
HTML Element
Here we will use an ul. You can use any HTML.
Just add the string and ReactSortable will use a ul instead of a div.
When using a custom component in the tag prop, the only component it allows is a forwardRef component.
Currently, we only support components that use the React.forwardRef API.
If it doesn't have one, you can add one using React.forwardRef().
todo: Some third-party UI components may have nested elements to create the look they're after.
This could be an issue and not sure how to fix it.
import React, { FC, useState, forwardRef } from "react";
import { ReactSortable } from "react-sortablejs";
// This is just like a normal component, but now has a ref.
const CustomComponent = forwardRef<HTMLDivElement, any>((props, ref) => {
return <div ref={ref}>{props.children}</div>;
});
export const BasicFunction: FC = (props) => {
const [state, setState] = useState([
{ id: 1, name: "shrek" },
{ id: 2, name: "fiona" },
]);
return (
<ReactSortable tag={CustomComponent} list={state} setList={setState}>
{state.map((item) => (
<div key={item.id}>{item.name}</div>
))}
</ReactSortable>
);
};
How does it work?
Sortable affects the DOM, adding, and removing nodes/css when it needs to in order to achieve the smooth transitions we all know an love.
This component reverses many of its actions of the DOM so React can handle this when the state changes.
Caveats / Gotchas
key !== index
DO NOT use the index as a key for your list items. Sorting will not work.
In all the examples above, I used an object with an ID. You should do the same!
I may even enforce this into the design to eliminate errors.
Nesting
Problem
Basically, the child updates the state twice. I'm working on this.
What does work?
Our usage indicates that as long as we only move items between lists that don't use the same setState function.
I hope to provide an example soon.
Solutions
We don't have anything that works 100%, but here I'd like to spitball some potential avenues to look down.
Use onMove to handle state changes instead of onAdd,onRemove, etc.
Create a Sortable plugin specifically for react-sortbalejs
SortableJS/react-sortablejs thuộc nhóm Frontend trên TopGit, cùng 5 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về SortableJS/react-sortablejs ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/SortableJS/react-sortablejs là nguồn chính thức.
SortableJS/react-sortablejs có bao nhiêu sao?
SortableJS/react-sortablejs có 2.2k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/SortableJS/react-sortablejs. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
SortableJS/react-sortablejs có những chủ đề gì?
GitHub topics của SortableJS/react-sortablejs: "drag-and-drop", "draggable", "multidrag", "react", "sortable". TopGit xếp repo vào nhóm Frontend.
SortableJS/react-sortablejs còn đang phát triển không?
Commit gần nhất trên SortableJS/react-sortablejs là 2.8 năm trước (theo timestamp GitHub). Repo có 215 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
SortableJS/react-sortablejs viết bằng ngôn ngữ gì?
SortableJS/react-sortablejs chủ yếu viết bằng TypeScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Vì sao SortableJS/react-sortablejs được xếp vào nhóm Frontend?
TopGit xếp SortableJS/react-sortablejs vào nhóm Frontend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "drag-and-drop", "draggable", "multidrag"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc react-sortablejs có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về react-sortablejs.