UNPKG

react-dnd

Version:
24 lines (23 loc) 960 B
import * as React from 'react'; import { memo } from 'react'; import { DndContext, createDndContext } from './DndContext'; /** * A React component that provides the React-DnD context */ export const DndProvider = memo(({ children, ...props }) => { const context = 'manager' in props ? { dragDropManager: props.manager } : createSingletonDndContext(props.backend, props.context, props.options, props.debugMode); return React.createElement(DndContext.Provider, { value: context }, children); }); const instanceSymbol = Symbol.for('__REACT_DND_CONTEXT_INSTANCE__'); function createSingletonDndContext(backend, context = getGlobalContext(), options, debugMode) { const ctx = context; if (!ctx[instanceSymbol]) { ctx[instanceSymbol] = createDndContext(backend, context, options, debugMode); } return ctx[instanceSymbol]; } function getGlobalContext() { return typeof global !== 'undefined' ? global : window; }