NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm · #4810 most downloaded on npm
Drag and Drop for React
Last release 4 years ago
no release in 18 months
Release timing varies
gaps range from 2 weeks to 9 months
Most releases are documented
notes for 51 of the last 60 stable releases
5 versions withdrawn
withdrawn after publishing
12 years old
140 releases · first in 2014
Nothing published for this version
## Major * Packages are now ESM-Only (https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) * Node 18 Support
One column per quarter.
@react-dnd/asap has been simplified to remove the node variant, which relied on deprecated APIs
The utility packages @react-dnd/invariant, @react-dnd/shallowequal, and @react-dnd/asap (which are forks of popular libraries) have been included in the monorepo and built using the same output mechanisms as the react-dnd core packages (dual EJS/CSM).
@react-dnd/asap has been simplified to remove the node variant, which relied on deprecated APIs
Nothing published for this version
All packages now have verified ESM support
pkg.exportsThis release uses output from swc using the 'es2017' target instead of using output from 'tsc' using the 'ESNext' target.
This release uses output from swc using the 'es2017' target instead of using output from 'tsc' using the 'ESNext' target.
This release fixes issues with the ESM-only structure of v15.0.0. All packages are now in their prior CommonJS/ESM format.
This release fixes issues with the ESM-only structure of v15.0.0. All packages are now in their prior CommonJS/ESM format.
~~The react-dnd packages are now published as ESM-only with type: module. See this FAQ by sindresorhus: https://gist.github.com/sindresorhus/a39789f98
The react-dnd packages are now published as ESM-only with type: module. See this FAQ by sindresorhus: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
The Decorators API has been removed and fully replaced by the Hooks API. The Decorators API was difficult to develop & type correctly, and this improves its maintainability.
The builds no longer use babel & preset-env. The library is transpiled using SWC into the "es2017" target, which assumes async/await is available. This should reduce bundle sizes by removing polyfills and support-code which may be unnecessary in your target.
canDrag is true (#3187)Nothing published for this version
Nothing published for this version
react-dnd: 14.0.3 react-dnd-html5-backend: 14.0.1 react-dnd-touch-backend: 14.1.0
react-dnd: 14.0.3 react-dnd-html5-backend: 14.0.1 react-dnd-touch-backend: 14.1.0
This PR will throw a developer exception if a user specifies a useDrag::spec.begin method.
This PR will throw a developer exception if a user specifies a useDrag::spec.begin method.
Update internal hook useDragType() to align with updated typings. Check 14.0.0 release for API changes
Update internal hook useDragType() to align with updated typings. Check 14.0.0 release for API changes
This release addresses a handful of nagging liveness and ergonomic issues with the hooks API.
This release addresses a handful of nagging liveness and ergonomic issues with the hooks API.
The liveness issues affect all hooks, and were discovered on deeper inspection of certain stress tests in the documentation. The internal useCollector() hook is used to collect props from the DnD system when things change. Prior to this update, we subscribed to updates from the DnD monitor to trigger prop collection. However, state on the react side was only accounted for on the first render. This release improves that liveness by collecting props whenever react state changes.
The ergonomics of the useDrag have been refactored. In short:
spec.type is requiredspec.item can be a function or static object.spec.item replaces spec.beginSince the release of the hooks API, we packed type under spec.item. However, this led to nonintuitive situations where an item field was required to be specified even though items are created in the begin method.
Additionally, in the original React-DnD design, beginDrag() was optional and the type of the draggables had to be defined. If no explicit DragObject was created, an implicit object was created by the system..
The change we've made here decouples type from item, and collapses begin into item.
// Pre-v14
useDrag({
// item defined here to get a type
item: { type: BOX } },
// ...but the actual item is created here
begin: () => ({ id })
})
// v14
useDrag({
type: BOX,
item: () => ({id})
})
e.g. useDrag({ item: { type: BOX }}) => useDrag({ type: 'BOX' })
We've also added the ability to cancel drag operations in the hooks API by returning null from begin.
// new API
useDrag({
type: BOX,
item: () => shouldNotDrag ? null : {id},
})
Re-register drag sources in hooks API when item.type changes
item.type changesHTML5Context, HTML5BackendOptions interfacesTLDR: useDrag and useDrop support both a memo pattern and a spec object now. `js useDrag(() => spec) // good useDrag(spec) // also good `
TLDR: useDrag and useDrop support both a memo pattern and a spec object now.
useDrag(() => spec) // good
useDrag(spec) // also good
In v13, we've tried to address some errors that were pervading with the react-dnd hooks API. Generally, making sure DragSource/DropTargets were up-to-date and that the system wasn't leaking handles was a precarious balancing act. Moving to a memo API pattern (e.g. useDrag(() => spec)) fixed this problem in our tests.
However, as we dug further into handler leakage issues, it became clear that anything using the hooks would reattach and receive a new handler ID whenever the spec changed at all. This was in contrast to the Decorator API's behavior of keeping stable handler IDs as the incoming props changed.
To fix the Hooks API to stop leaking handlers, we found a pretty simple solution: a classical class with a public setter for the spec object that's updated via a useEffect hook. This neatly avoids the mutating DragSource/DropTargets on every spec change. This had two effects: identifiers have been stabilized, and spec objects were usable again because changing them didn't cause DragSource/DropTarget instances to be regenerated and reattached.
In retrospect, this undoes the necessity of the major cut that happened with v13, but the Hooks API is much sturdier now. We hope that you find the improved memory stability in the hooks API to be useful in your projects.
Add invariant() invocations in useDrag, useDrop to verify that spec functions are used instead of objects
v12 was largely structural and organizational, but some issues were discovered shortly after release that warranted changing the hooks API.
v12 was largely structural and organizational, but some issues were discovered shortly after release that warranted changing the hooks API.
useDrag, useDrop hooks accept functions that create spec objects instead of spec objects directly. Clients can think about the API to useDrag() and useDrop() as being analogous to useMemo(). This allows clients to have direct control over when their DnD specifications are re-generated (which internally reattaches them to the DnD system).rootElement component in the HTML5Backend options to localize where DnD will process events in the client app.Nothing published for this version
Update .npmignore files so that tsbuildinfo files are not included in publication. This reduces package sizes.
Update .npmignore files so that tsbuildinfo files are not included in publication. This reduces package sizes.
Nothing published for this version
Add getDecoratedComponent() method to wrapInTestContext imperative API.
getDecoratedComponent() method to wrapInTestContext imperative API. (#2488)wrapInTestContext(#2486)react-dnd (#2491)Update Backends to use named exports for BackendFactory functions instead of default exports.
Update Backends to use named exports for BackendFactory functions instead of default exports.
e.g.
import HTML5Backend from 'react-dnd-html5-backend
👇
import { HTML5Backend } from 'react-dnd-html5-backend
In general, throughout the app we've minimized the usage of default exports as well. They interfere with type correctness and screw with UMD builds (e.g. having to scrape a .default property off of a UMD global).
useDragDropManager at top leveldnd-core: Use updated version @react-dnd/asap with browser variant support, this allows us to drop syntheticDefaultImports in dnd-core.
dnd-core: Use updated version @react-dnd/asap with browser variant support, this allows us to drop syntheticDefaultImports in dnd-core.
Fix UMD builds - our fork of ASAP was being brought in with node-specific code, breaking UMD builds. Using the canonical version of ASAP until we upda
Fix UMD builds - our fork of ASAP was being brought in with node-specific code, breaking UMD builds. Using the canonical version of ASAP until we update our fork (#1684 )
The package.type=module setting has been removed. This proved to be a major pain point for users, and was technically problematic at this time. We wil
The package.type=module setting has been removed. This proved to be a major pain point for users, and was technically problematic at this time. We will eventually ship with package.type=module when NodeJS 12 drops out of maintenance and all of our dependencies ship ESM. (#1683)
The touch-backend has been updated to work-around iOS 13.x eventing issues (#1631) (thanks @zhusee2!)
Remove syntheticDefaultImport usage of react in react-dnd (#1629) thanks @sandersn . Fully removing syntheticDefaultImport from react-dnd is a WIP. We
syntheticDefaultImport from react-dnd is a WIP. We will need pure ESM versions of asap and hoist-non-react-statics. Ideally invariant and shallowequal would have ESM builds available as well, but there are forked ESM variants of these packages.Declare packages side-effect free for tree-shaking (#1577), thanks @maclockard
UMD builds are now shipped with the _react-dnd_, _react-dnd-html5-backend_, and _react-dnd-touch-backend_ packages in addition to _react-dnd-umd-build
(Typings) - Add getTargetIds to DragSourceMonitor interface declaration
Fixed some issues in react-dnd where named exports of interfaces were causing JS breakage
Add CJS builds to the core packages in order to facilitate better testing. (#1455, #1460)
All libraries
Redefine XYCoord interface in react-dnd interfaces
The react-dnd toolchain has been changed up from using TypeScript to using Babel. This allows us to use a ‘browserlist’ query instead of a coarse tsc
All Libraries Affected
The react-dnd toolchain has been changed up from using TypeScript to using Babel. This allows us to use a ‘browserlist’ query instead of a coarse tsc target when defining what JS features to ship with. The public API has not changed at all, but there could be underlying changes if your code is implementation dependent.
Correct an issue where drag previews were disconnected if the dragSource changed
Remove DragDropContext decorator.
DragDropContext decorator. (#1439)dnd-core to accept a configuration object. (#1439)DragDropManagerImpl class (#1439)react-dnd-touch-backend libraryDndProvider to accept an 'options' prop with backend configurationThe DndProvider component had been throwing errors if it was rendered multiple times because of the implicit singleton invariant of the HTML5Backend.
<DndProvider backend={HTML5Backend}/>, it will only create a singleton instance of the DndContext per global context. This means that to create a second backend for an iframe, one needs to use:
<DndProvider backend={HTML5Backend} context={iframeWindow} />.The CommonJS libraries had runtime issues due to some @ts-ignore statements on non-typed module imports. Those have been removed from the core librari
The CommonJS libraries had runtime issues due to some @ts-ignore statements on non-typed module imports. Those have been removed from the core libraries.
__ES Modules__. The target output of TypeScript has been changed to esnext with esnext modules. This speeds up and simplifies our build process, and t
DragDragDropContextProvider~ => DndProviderDragDropContext, DragDropContextConsumer, and DragDropContextProvider~ => DndContext.The package.json files for the react-dnd libraries contained a "module" field which was used to identify where the ES Module roots began. These fields
The package.json files for the react-dnd libraries contained a "module" field which was used to identify where the ES Module roots began. These fields were added with the intent of supporting CommonJS module loading (the de-facto NodeJS module system) simultaneously with the ES Module loading system (the emerging standard for JavaScript modules).
Unfortunately this change resulted in a lot of build headaches for users then their module bundlers started defaulting to using the ES Module roots.
This release reverts that change and leaves the v7 branch of React-Dnd as primarily using CommonJS. ES Module builds are still available under the esm/ folders, but it is up to users to use them at their own discretion.
In v8, ES Modules are used as the default module system. CommonJS-based packages are still available however in react-dnd-cjs, and react-dnd-html5-backend-cjs
Nothing published for this version
Release the Hooks API (#1381) (a5b0242), closes #1381
Allow __DragDropContextProvider__ to accept a manager prop
manager prop (#1362)Replace some remaining lodash imports with our internal replacements.
Replace lodash with custom functions
getDecoratedComponentInstance() would throw invariant errors when used internallyString.endsWith polyfill for semver compatFixes an issue when using function components utilizing React.forwardRef as DragSource/DropTargets. The React-DnD wrapper class was being passed as th
Fixes an issue when using function components utilizing React.forwardRef as DragSource/DropTargets. The React-DnD wrapper class was being passed as the ref instance to hover instead of the decorated component instance.
Fixed an issue where refs were being attached to function components via the DragLayer and DragDropContext.
Nothing published for this version
Add a third argument to the collector functions in DragSource and DropTarget that includes the props of the current component. (e.g. collect(connect,
collector functions in DragSource and DropTarget that includes the props of the current component. (e.g. collect(connect, monitor, props)connectDragSource(ref))DragPreviewImage renderless component that wires up Drag Preview images.react-dnd-test-utils package, which exposes the wrapInTestContext utility function#1265 - Update ConnectDragSource/ConnectDropTarget typings to include null and Element consistently. #1266 - Update the experimental hooks API dragSou
#1265 - Update ConnectDragSource/ConnectDropTarget typings to include null and Element consistently.
#1266 - Update the experimental hooks API dragSource specification so that begin may return a dragObject.
Updates to the non-stable, hooks-based API.
Updates to the non-stable, hooks-based API.
Add useDragPreview hook.
useDrag
begin() function is now optional, and returns void.end() is the DragResulttype property has been removeditem property, which must contain a type fieldref field optional, if this is not set, then one will be created.useDrop
type property has been renamed acceptdrop, hover and canDrop functions now take the DragItem as the first argument.ref field optional, if this is not set, then one will be created.Add DragDropContextConsumer to the top-level react-dnd export
Minor Changes
DragDropContextConsumer to the top-level react-dnd export (#1260)Patch Changes
This patch release puts the experimental hooks API behind an annoying import so that it's clear to users that this API should not be used in productio
This patch release puts the experimental hooks API behind an annoying import so that it's clear to users that this API should not be used in production yet.
import { __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__ } from 'react-dnd'
const { useDrag, useDrop } = __EXPERIMENTAL_DND_HOOKS_THAT_MAY_CHANGE_AND_BREAK_MY_BUILD__
...
The hooks API will is currently __experimental__, and breaking changes of hooks may occur in non-major versions.
[patch] - #1249 - Check for uninitialized source/target identifiers
[patch] - #1250 - Use ES5 target for CommonJs builds.
[minor] - #1251, #1244, #1173 - Experimental Hooks API
This release includes an experimental hook-based React-Dnd API. Documentation for this feature still needs to be created, but the three public facing hooks are: useDragSource, useDropTarget, and useDragLayer.
The hooks API will is currently experimental, and breaking changes of hooks may occur in non-major versions.
const ref = useRef(); // pass in a ref instead of connectDragSource()
const { isDragging } = useDragSource(ref, ItemTypes.KNIGHT, {
beginDrag(monitor){ /* */ },
// collect function defined in specification
collect: monitor => ({
isDragging: monitor.isDragging(),
}),
})
return <div ref={ref}>...</div>
const ref = useRef(); // pass in a ref instead of connectDropTarget()
const { isOver, canDrop } = useDropTarget(ref, ItemTypes.KNIGHT, {
canDrop: () => canMoveKnight(props.x, props.y),
drop: () => moveKnight(props.x, props.y),
// collect function defined in specification
collect: monitor => ({
isOver: monitor.isOver(),
canDrop: monitor.canDrop(),
}),
})
return <div ref={ref}>...</div>
const props = useDragLayer(monitor => ({
item: monitor.getItem(),
itemType: monitor.getItemType(),
initialOffset: monitor.getInitialSourceClientOffset(),
currentOffset: monitor.getSourceClientOffset(),
isDragging: monitor.isDragging(),
}))
Add EsModule builds in addition to CommonJS builds
dropEffect=none setting on native DnD events (#1240)dataTransfer.items for files (#1241)dataTransfer.items for files (#1241) (96ff9ca), closes #1241 #712License Update The library was originally licensed as MIT, but during the transition to a Monorepo, the license was set to BSD 3-Clause. This release
License Update The library was originally licensed as MIT, but during the transition to a Monorepo, the license was set to BSD 3-Clause. This release corrects that error and restores the MIT license across all packages.
Nothing published for this version
Add 'debugMode' option to DndContext (#1190) (572955b), closes #1190
This required dropping support of TypeScript decorators in our examples, and may cause breaking changes for TypeScript users. The core issue is that T…
autobind-decorator library with class bind semantics, which eliminates that dependency.publishSource to true when options passed to beginDrag (#1161) (76cca25), closes #1161Restore support for react Stateless Functional Components.
Your coding agent can read these notes before it upgrades. Set up the MCP server →