Skip to content

Instantly share code, notes, and snippets.

@srph
Created February 19, 2023 02:12
Show Gist options
  • Save srph/1cce7fcf97c83bff86b7a36364739c5c to your computer and use it in GitHub Desktop.
Save srph/1cce7fcf97c83bff86b7a36364739c5c to your computer and use it in GitHub Desktop.
data structure for drag and drop feature with react-query
// 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