Created
September 8, 2019 17:55
-
-
Save crazypixel/76b193522f01fb2284db7500168ea272 to your computer and use it in GitHub Desktop.
dnd hooks sortable
This file contains 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
const handleDrag = useCallback(({translation, id}) => { | |
const delta = Math.round(translation.y / HEIGHT); | |
const index = state.order.indexOf(id); | |
const dragOrder = state.order.filter(index => index !== id); | |
if (!inRange(index + delta, 0, items.length)) { | |
return; | |
} | |
dragOrder.splice(index + delta, 0, id); | |
setState(state => ({ | |
...state, | |
draggedIndex: id, | |
dragOrder | |
})); | |
}, [state.order, items.length]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment