reworking on drag context

This commit is contained in:
paul
2024-09-16 12:23:15 +05:30
parent f692af7f3f
commit f79b6514db
10 changed files with 184 additions and 151 deletions

View File

@@ -0,0 +1,24 @@
import React, { createContext, useContext, useState } from 'react';
const DragContext = createContext()
export const useDragContext = () => useContext(DragContext)
// Provider component to wrap around parts of your app that need drag-and-drop functionality
export const DragProvider = ({ children }) => {
const [draggedElement, setDraggedElement] = useState(null)
const onDragStart = (element) => {
setDraggedElement(element)
}
const onDragEnd = () => {
setDraggedElement(null)
}
return (
<DragContext.Provider value={{ draggedElement, onDragStart, onDragEnd }}>
{children}
</DragContext.Provider>
)
}