question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drag source is not rendering at all

See original GitHub issue

Describe the bug Component decorated with DragSource is not rendered at all (render function is not called)

To Reproduce Write such component:

import * as React from "react";
import styled from "styled-components";
import {
  DragSource,
  DragSourceConnector,
  DragSourceMonitor,
  ConnectDragSource
} from "react-dnd";

const ImageHolder = styled.div`
  margin: 10px;
  max-width: 200px;
  width: 200px;
  min-height: 100px;
  position: relative;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
`;

const ImageNameHolder = styled.div`
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px;
  background-color: rgba(0, 0, 0, 0.5);
  font-size: 13px;
`;

interface Props {
  imagePath: string;
  connectDragSource?: ConnectDragSource;
  isDragging?: boolean;
}

@DragSource<Props>(
  "image",
  {
    beginDrag: (props: Props) => props.imagePath
  },
  (connect: DragSourceConnector, monitor: DragSourceMonitor) => ({
    connectDragSource: connect.dragSource(),
    isDragging: monitor.isDragging()
  })
)
export class PhotosBrowserPhoto extends React.Component<Props> {
  render() {
    const { imagePath, connectDragSource } = this.props;
    console.log({ connectDragSource });
    return connectDragSource(
      <div>drag me</div>
    );
  }
}

Expected behavior Draggable component with drag me text, connectDragSource printed in the console

Actual behavior Nothing is rendered at all, console is empty

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

22reactions
theoutlandercommented, Oct 2, 2018

I had to add the provider as shown below:

import HTML5Backend from 'react-dnd-html5-backend'
import { DragDropContextProvider } from "react-dnd";

<DragDropContextProvider backend={HTML5Backend}>
 <App/>
</DragDropContextProvider>
19reactions
pie6kcommented, Oct 2, 2018

Adding provider component in root of my app solved the issue.

I think however - it should be clearly noted in example code that it’s needed - I thought seeing example is enough to understand how to start using library

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Drag and Drop not working - Component rendering ...
Simple React DND form builder. The values when dropped, gets rendered twice. Any help is much appreciated. javascript · reactjs · react- ...
Read more >
Mastering Drag & Drop with ReactJS | by Shay Keinan
I'm using styled-components for styling, we can pass props to the CSS and use them. Because we are going to render this component...
Read more >
Rendering and previewing sequences - Adobe Support
In this Help article, learn how to render, preview, and playback sequences in Premiere Pro.
Read more >
How To Fix Adobe Premiere Render and Export Errors (2022)
In this Adobe Premiere tutorial, I show you how to fix common render and export errors! Comment below with which fix worked for...
Read more >
6 Proven Ways to Fix Sony Vegas Not Rendering Whole Video
Solution 1. Disable Render Loop Region Only. The Sony Vegas not rendering the whole video error can happen for several reasons, but in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found