tajo / react-movable

🔀 Drag and drop for your React lists and tables. Accessible. Tiny.
https://react-movable.pages.dev
MIT License
1.53k stars 51 forks source link

TypeError: Cannot read properties of null (reading 'getBoundingClientRect') #76

Closed nathanburgess closed 1 year ago

nathanburgess commented 2 years ago

Getting this error when attempting to drag using a drag handler.

<List
  values={operations}
  onChange={({ oldIndex, newIndex }) => {
    onMoveOperation?.(operations[oldIndex], operations[newIndex]);
  }}
  renderList={({ children, props }) => <div {...props}>{children}</div>}
  renderItem={({ value: operation, props, isDragged }) => {
    return (
      <FilterRowWrapper {...props}>
        <FilterDragHandleWrapper data-movable-handle isDragged={isDragged}>
          <DragHandleIcon />
        </FilterDragHandleWrapper>
      </FilterRowWrapper>
    )
  }}
/>

operations always has some value and I cannot figure out what's causing this issue.

NB: This did work previously when using a component from Chakra, which we're in the process of stripping out of our project.

nghieptiki commented 2 years ago

@nathanburgess FilterRowWrapper should be wrapped by forwardRef

const FilterRowWrapper = forwardRef(funnction FilterRowWrapper(props, ref) {
return <div ref={ref}>...</div>
} )