Created
February 19, 2023 02:12
-
-
Save srph/1cce7fcf97c83bff86b7a36364739c5c to your computer and use it in GitHub Desktop.
data structure for drag and drop feature with react-query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// API | |
{ | |
items: [] | |
} | |
// Query | |
{ | |
items: { | |
[id]: { | |
id: 1, | |
name: 'Item 1', | |
description: 'Item 1 description', | |
price: 100, | |
image: 'http://example.com/image.jpg' | |
}, | |
} | |
} | |
// Render | |
const categories = [ | |
5, 3, 1, 2, 4 | |
] | |
const items = [ | |
6a, 2b, 3d, 4e, 1c | |
] | |
const item = data.items[id] | |
categories.map(cid => { | |
const category = data.items[cid] | |
return ( | |
<> | |
<DragAndDropContainer> | |
<DragHandler /> | |
{items.map(iid => { | |
const item = data.items[iid] | |
return ( | |
<DragAndDropContainer> | |
</DragAndDropContainer> | |
) | |
})} | |
</DragAndDropContainer> | |
</> | |
) | |
}) | |
// Is it a bad idea to ever call invalidateQueries in a drag and drop software? | |
// Never mind |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment