Socket
Socket
Sign inDemoInstall

react-dnd-html5-backend

Package Overview
Dependencies
6
Maintainers
5
Versions
79
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-dnd-html5-backend

HTML5 backend for React DnD


Version published
Weekly downloads
1.8M
decreased by-1.03%
Maintainers
5
Install size
796 kB
Created
Weekly downloads
 

Package description

What is react-dnd-html5-backend?

The react-dnd-html5-backend package is a backend implementation for react-dnd (React Drag and Drop) that uses the HTML5 drag and drop API. It enables you to implement drag and drop functionalities in your React applications using the native HTML5 API.

What are react-dnd-html5-backend's main functionalities?

Drag Source

This code sample demonstrates how to create a draggable component using the useDrag hook from react-dnd. The component becomes a drag source that can be dragged around the screen.

import { useDrag } from 'react-dnd';

function DraggableComponent() {
  const [{ isDragging }, drag] = useDrag(() => ({
    type: 'BOX',
    collect: (monitor) => ({
      isDragging: !!monitor.isDragging(),
    }),
  }));

  return (
    <div ref={drag} style={{ opacity: isDragging ? 0.5 : 1 }}>
      Draggable Content
    </div>
  );
}

Drop Target

This code sample shows how to create a drop target using the useDrop hook from react-dnd. The component can accept draggable items and provides visual feedback when an item is dragged over it.

import { useDrop } from 'react-dnd';

function DroppableComponent() {
  const [{ canDrop, isOver }, drop] = useDrop(() => ({
    accept: 'BOX',
    drop: () => ({ name: 'DroppableComponent' }),
    collect: (monitor) => ({
      isOver: monitor.isOver(),
      canDrop: monitor.canDrop(),
    }),
  }));

  return (
    <div ref={drop} style={{ backgroundColor: isOver ? 'green' : 'white' }}>
      {canDrop ? 'Release to drop' : 'Drag a box here'}
    </div>
  );
}

Custom Drag Layer

This code sample illustrates how to use a custom drag layer to render a custom preview of the draggable item. The useDragLayer hook provides the necessary state to render the preview at the correct position.

import { useDragLayer } from 'react-dnd';

function CustomDragLayer() {
  const { isDragging, item, currentOffset } = useDragLayer((monitor) => ({
    item: monitor.getItem(),
    currentOffset: monitor.getSourceClientOffset(),
    isDragging: monitor.isDragging(),
  }));

  if (!isDragging) {
    return null;
  }

  return (
    <div style={{ position: 'fixed', pointerEvents: 'none', left: currentOffset.x, top: currentOffset.y }}>
      Custom Drag Layer Content
    </div>
  );
}

Other packages similar to react-dnd-html5-backend

Readme

Source

npm package Build Status dependencies Status devDependencies Status peerDependencies Status

React DnD HTML5 Backend

The officially supported HTML5 backend for React DnD. See the docs for usage information.

Installation

If you use npm:

npm install --save react-dnd-html5-backend

Browser Support

We strive to support the evergreen browsers.

Unfortunately the browser bugs, inconsistencies, and regressions come up from time to time, so please make sure you test your app on the browsers you’re interested in, and report any bugs to us.

License

MIT

FAQs

Last updated on 19 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc