Skip to content

Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? #233

@MartensCedric

Description

@MartensCedric

I might be doing something wrong but I cannot get this library to work

The code used:

export default class App extends Component {    
      
     handleCanvas = (canvas) => {    
     const ctx = canvas.getContext('2d');    
     ctx.fillStyle = 'purple';    
     ctx.fillRect(0, 0, 100, 100);    
    }    
      
   render() {    
     return (    
       <Canvas ref={this.handleCanvas}/>    
     )    
    }    
  }    

I'm getting this error:

Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

This is the tutorial so I'm a bit confused on why I am getting this problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions