diff --git a/packages/ra-tree-ui-materialui/src/DragLayer.js b/packages/ra-tree-ui-materialui/src/DragLayer.js index 446378f734a..8f44f265e18 100644 --- a/packages/ra-tree-ui-materialui/src/DragLayer.js +++ b/packages/ra-tree-ui-materialui/src/DragLayer.js @@ -2,13 +2,13 @@ * Custom DragLayer from Alejandro Hernandez * See https://github.com/react-dnd/react-dnd/issues/592#issuecomment-399287474 */ -import React, { Component } from 'react'; +import React from 'react'; import PropTypes from 'prop-types'; import { DragLayer } from 'react-dnd'; -import compose from 'recompose/compose'; -import { withStyles } from '@material-ui/core/styles'; +import { makeStyles } from '@material-ui/core/styles'; import isEqual from 'lodash/isEqual'; -const styles = { + +const useStyles = makeStyles({ layer: { position: 'fixed', pointerEvents: 'none', @@ -19,56 +19,51 @@ const styles = { height: '100%', }, item: {}, -}; - -class CustomDragLayer extends Component { - static propTypes = { - beingDragged: PropTypes.bool, - classes: PropTypes.object.isRequired, - dragPreviewComponent: PropTypes.oneOfType([ - PropTypes.element, - PropTypes.func, - ]).isRequired, - itemBeingDragged: PropTypes.object, - offset: PropTypes.object, - }; +}); - shouldComponentUpdate(nextProps) { - return !isEqual(this.props.offset, nextProps.offset); - } +function CustomDragLayer({ + classes: classesOverride, + beingDragged, + dragPreviewComponent: DragPreview, + itemBeingDragged, + offset, +}) { + const classes = useStyles({ classes: classesOverride }); - render() { - const { - classes, - beingDragged, - dragPreviewComponent: DragPreview, - itemBeingDragged, - offset, - } = this.props; - if (!beingDragged || !offset) return null; + if (!beingDragged || !offset) return null; - return ( -