react-dnd-preview is a dedicated component for creating drag-and-drop previews within applications utilizing React DnD. It simplifies the implementation of visual feedback during drag operations by providing a component that renders the dragged item at the current mouse position. The current stable version is 9.0.0, which includes support for React v19. Releases typically follow the React and React DnD release cycles for major versions, with minor and patch updates for bug fixes and dependency bumps occurring more frequently. Its key differentiator is its tight integration with the React DnD ecosystem, offering a straightforward way to add preview functionality without complex manual DOM manipulation, making it an essential companion for sophisticated drag-and-drop UIs.
npm install react-dnd-previewVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic draggable box with a custom preview generated by `react-dnd-preview`, using `DndProvider` and `HTML5Backend`.
Upgrade your React installation to v19 or compatible version. If you are not ready for React v19, stick to `react-dnd-preview` v8.x.
Migrate your import statements to ES Modules syntax (e.g., `import { Preview } from 'react-dnd-preview';`). Ensure your project's build system supports ESM.Update `react-dnd` to `^16.0.1` or higher. Upgrade your Node.js runtime to at least v16.
If you encounter errors related to `dnd-core` not being found, install it: `npm install dnd-core` or `yarn add dnd-core`.
Utilize the `placement` prop (e.g., `<Preview generator={generatePreview} placement="top left" />`) to control the preview's position relative to the cursor or origin.Update your import statements to use ES Modules syntax: `import { Preview } from 'react-dnd-preview';` and ensure your bundler (Webpack, Rollup, Vite) is configured for ESM.Ensure that `react-dnd`'s `DndProvider` is wrapping your components, and that `react-dnd-preview`'s `Preview` component is rendered within it. Verify your `generator` function handles all expected item types and states correctly.
Ensure `react-dnd-preview` is installed correctly and your `tsconfig.json` includes `node_modules` in its `typeRoots` or `types` configuration. Sometimes, a simple reinstall (`npm install react-dnd-preview`) or IDE restart helps.