I think I'm misunderstanding how refs are supposed to work. In a component, I'm returning:
return <canvas ... ref={(ref) => this._canvas = ref}/>
Later, in componentDidMount
, I attempt to access the ref as:
this._canvas.getContext('2d')
which errors out because this._canvas
refers to some kind of constructor as shown below:
- What is the best way to save a reference to the actual canvas element so I can do things like
getContext
later on, and - What exactly is that constructor function, and what is its purpose?
I noticed that calling this._canvas.getDOMNode()
returns the actual element, which seems to be what I'm looking for. However, I'd rather not go through and replace all references to this._canvas
without fully understanding what I'm doing.