Using object array instead of a string array for id?
See original GitHub issueMy sortable item has several props exposed such as title, category and image.
So instead of
[items, setItems] = useState(['1', '2', '3']);
My sortable item looks like:
[items, setItems] = useState([
{id: '1', title: 'x', category: 'y'},
{id: '2', title: 'z', category: 'w'}
...])
I am not sure how I can make this work.
Any help would be appreciated!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to get an array of IDs as strings instead of object with ...
I want the result to be an array. There reason why I want it to be a list is that I want to...
Read more >Data Structures: Objects and Arrays - Eloquent JavaScript
The elements in an array are stored as the array's properties, using numbers as ... You give it an object, and it returns...
Read more >Array.prototype.filter() - JavaScript - MDN Web Docs
The filter() method creates a shallow copy of a portion of a given array, filtered down to just the elements from the given...
Read more >5. Working with Arrays and Loops - JavaScript Cookbook [Book]
An array is an ordered collection of elements. In JavaScript, an array can be created using formal object notation, or it can be...
Read more >How to print object by id in an array of objects in JavaScript?
How to pretty print JSON string in JavaScript ? ... JavaScript | How to add an element to a JSON object? ... How...
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
fixed it with following code:
As mentioned by @TheUrbina20, the solution is to map the items to their corresponding unique identifiers.
You may want to memoize to avoid needless re-renders of the SortableContext: