New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drag source is not rendering at all #1132
Comments
Same thing is happening to me, though I'm using ES6 syntax: import React, { Component } from "react";
import { DragSource } from "react-dnd";
import PropTypes from "prop-types";
import "./Dictionary.css";
const propTypes = {
entry: PropTypes.object.isRequired,
// Injected by React DnD:
isDragging: PropTypes.bool.isRequired,
connectDragSource: PropTypes.func.isRequired
};
const TYPES = {
ROW: "row"
};
/**
* Implements the drag source contract.
*/
const rowSource = {
beginDrag(props) {
console.log(props);
return {
entry: props.entry
};
}
};
/**
* Specifies the props to inject into your component.
*/
function collect(connect, monitor) {
return {
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging()
};
}
class Row extends Component {
constructor(props) {
console.log("here");
super(props);
this.state = {
entry: props.entry
};
}
static getDerivedStateFromProps = (props, state) => {
return {
entry: props.entry
};
};
render() {
const { isDragging, connectDragSource } = this.props;
const { entry } = this.state;
console.log("dragging:", isDragging);
return connectDragSource(
<div style={{ opacity: isDragging ? 0.5 : 1 }} className="row">
<div>{entry.string}</div>
<div>{entry.kMandarin}</div>
<div>{entry.kDefinition}</div>
</div>
);
}
}
Row.propTypes = propTypes;
export default DragSource(TYPES.ROW, rowSource, collect)(Row); Using:
Expected: see rendered component and console logs |
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 |
I think the problem is this
It looks like it disables a check that would otherwise throw an error if there's no context. |
I had to add the provider as shown below:
|
fyi: I just encountered the issue when using Portals and fixed it by replacing the outdated |
Why didn't I spend a lot of time for troubleshooting rendering reason, found the answer here, please do your sample some seriously, thank you |
Seems to be present against React 16.8.1, my manager is never created and the Context.Consumer inside the |
This isn't anywhere in the Quick Start section of the docs. This is practically the first thing that ought to be in the docs... |
I also encountered the same bug. It is my environment.
const render = () => {
ReactDOM.render(
<DragDropContextProvider backend={HTML5Backend}>
<Provider store={store}>
<ConnectedRouter history={history}>
<AppContainer>
<App />
</AppContainer>
</ConnectedRouter>
</Provider>
</DragDropContextProvider>,
document.getElementById('app')
);
}; DragDropContextProvider is Unknown |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Anyone knows if that has been solved before it gets automatically closed ? |
How I have solved The problem was originated by the useDrag import path... Not working import Working import That said, I really don't know how the first import was originated. Also, I can safely say that you don't need to import the DndProvider in the app root. I've done that before to found that the problem was originated by the import, but after the import "fix", I've restored the DndProvider in one of the components instead of the app root (for a cleaner code) and that's works fine. Context:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
any solution yet? nothing suggested in this topic helped. "react-dnd": "^11.1.3", everything works fine only when I change the state position, I can't see the render while I can see the changes in console logs. |
Describe the bug
Component decorated with
DragSource
is not rendered at all (render function is not called)To Reproduce
Write such component:
Expected behavior
Draggable component with
drag me
text,connectDragSource
printed in the consoleActual behavior
Nothing is rendered at all, console is empty
The text was updated successfully, but these errors were encountered: