Skip to content

getcontext of a canvas gives TypeError: canvas.getContext is not a function #300

Open
@aymeric75

Description

@aymeric75

Hello,

I need to retrieve the context of a canvas, here is what I have tried:

import React, { Component } from 'react';
import Canvas from 'react-native-canvas';
import { View } from 'react-native';


class MyCanva extends Component {
  handleCanvas = (canvas) => {
    const ctx = canvas.getContext('2d');
    ctx.fillStyle = 'purple';
  }
  render() {
    return (
      <Canvas ref={this.handleCanvas}/>
    )
  }
}

export default function somefunction() {
  
  let canvas = new MyCanva();
  const context = canvas.getContext('2d');
  
  return (
    <View>
    </View>
  )
}

But it gives this error:
ERROR TypeError: canvas.getContext is not a function. (In 'canvas.getContext('2d')', 'canvas.getContext' is undefined)

Any idea where this comes from ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions