question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drawing on canvas or Refs and the DOM

See original GitHub issue

I’ve found very cool examples here using SVG animation. However not found any canvas ~animation~ drawing examples.

I’m trying to develop hyperapp PieCountdown component as this one.

In React I would use Refs to get access to canvas DOM element.

class Countdown extends Component {
  componentDidMount() {
    const ctx = this.canvas.getContext('2d');
    // draw something to canvas
    // ...
  }
  render() {
    return (
      <canvas ref={(canvas) => { this.canvas = canvas; }} />
    );
  }
};

export default Countdown;

Is it possible to get access to raw DOM elements in hyperapp, or what is recommended way to do canvas ~animations~ drawing?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:48 (33 by maintainers)

github_iconTop GitHub Comments

2reactions
zacenocommented, Jul 19, 2017

@mauron85 Yup that’s right. I called it “top-node” specifically to avoid confusion with root (which is an element – not a virtual dom node, btw). But yeah. The first, topmost h(... call or <div.. inside your view: (state, actions) => ... is the thing that can’t be keyed nor have onremove bound to it.

I agree that’s kind of unexpected. I mean I get why it is, but I had never thought of it until your examples.

2reactions
jorgebucarancommented, Jul 19, 2017

@zaceno Apparently we stopped doing that though. I missed that change. When was that, @jbucaran ?

Recent commit, before 0.10.0 I think. This was an undocumented thing, so can’t complain. 😉😏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using React With Canvas Element - Anton Lavrenov Blog
It allows you to draw DOM-like objects (images, texts) on canvas element in very performant way. It is NOT about drawing graphics, but...
Read more >
Using React Hooks with canvas - Koen van Gilst
For that we have to use a ref , which is a reference to the actual canvas DOM element. Now that we have...
Read more >
Canvas with React.js - Medium
We need a canvas element to draw inside it, so we must create a component ... The React way to get a dom...
Read more >
Build a Drawing App with React - YouTube
Build a Drawing App with ReactIn this video I show you how to build ... Add code for drawing on canvas 22:20 Draw...
Read more >
Bindings/Refs - SolidJS · Reactive Javascript Library
You can always get a reference to a DOM element in Solid through assignment, since JSX creates actual ... <canvas ref={canvas} width="256" height="256"...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found