1

I am trying to create a draggable list using Material UI and react-beautiful-dnd. I followed the tutorial on their page and created this-

function DraggableList(props) {
  const { classes, tableHeaders, tasksList } = props;
  return (
    <div>
      <Droppable droppableId="id">
       {(provided) => (
         <div ref={provided.innnerRef} {...provided.droppableProps}>  
           {tasksList && tasksList.slice(0,5).map((row, index) => (
              <Draggable draggableId={row.id} index={index}>
                {(provided)=> (
                  <div index={index} {...provided.draggableProps} {...provided.dragHandleProps} ref={provided.innerRef}> 
                    <Paper className={classes.root} key={row.id}>
                      <Grid container xs={12} className={classes.topContainer}>
                        <Grid item xs={2}>
                          <IconButton><DragIndicatorIcon className={classes.dragIcon}/></IconButton> </Grid>
                        <Grid item xs={10}>
                          <Typography className={classes.activity} variant="body2">{row.name}</Typography>
                        </Grid>
                      </Grid>
                    </Paper>
                   </div>
                )}
              </Draggable>
            ))}
          </div>
        )}
      </Droppable>
    </div>
  );
}

It keeps giving me

Error: Invariant failed: 
    provided.innerRef has not been provided with a HTMLElement.

    You can find a guide on using the innerRef callback functions at:
    https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/guides/using-inner-ref.md

error though I am setting innerRef on a 'div' . What is the mistake here

Kimaya
  • 1,210
  • 4
  • 14
  • 33

4 Answers4

3

Typo:

ref={provided.innnerRef}
asliwinski
  • 1,662
  • 3
  • 21
  • 38
1

I had the same problem, but my solution was quite different. I made the silly mistake of using curly bracket instead of parentheses. So I did:

{(provided) => {

And not:

{(provided) => (

No error indications whatsoever other than "provided.innerRef has not been provided with a HTMLElement."

lorecaster
  • 11
  • 1
0

You put

provided={provided}

in the same div it will start working. I also had the same issue but it got resolved with this.

SatyaDash
  • 190
  • 5
0

I had the same problem and I used styled-components. I just set the ref prop on the styled-component element and it worked for me.

I mean this:

const StyledElement = styled.div`
   //the css goes in here
`; 

<StyledElement ref={provided.innerRef} {...provided.droppableProps}>
   //The rest of the code goes here
<StyledElement/>