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.

How is Layer.add accessed?

See original GitHub issue

I’ve been trying to add a new shape object to an existing Layer in response to a click event. (Feel free to tell me that’s not how this package works 🤣) Just a quick sample to demonstrate what I’ve tried:

import React from 'react';
import { render } from 'react-dom';
import { Stage, Layer, Circle } from 'react-konva';

const myLayer = <Layer />;

const App = () => <Stage>{myLayer}</Stage>;

render(<App />, document.getElementById('root'));

// Later when the user clicks on something, but we can try this now why not
const myNewRuntimeElement = <Circle/>;

myLayer.add(myNewRuntimeElement);

BUT, this yeilds an error: TypeError: myLayer.add is not a function

“Okay, well if its not here, where do I go?”

I tried reaching into the Layer ref…


let myLayerRef;
const myLayer = <Layer ref={node => myLayerRef = node}/>;
...
myLayerRef.add(myNewRuntimeElement);

…Which has the add function defined, but gives an error: TypeError: child.getParent is not a function.

I get the same error if I pass the circle’s ref to add, but that feels like a react anti-pattern rabbit hole I’d prefer not to go down. Is this something I can accomplish with this tool, and if so, how?

Thanks! 😄

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
edemlockcommented, Apr 18, 2019

Hello @victormanuelfrancodev okay, thanks it is clear! The rect is drawn on the layer by an array, but I want to draw it as many times as I click on my image Or how do I write the function that I call on onClick()? So what do I write to my onClick function which is also in the render()?

Because I tried some solutions, but none of them worked and I confused. This is my first program in react. I’m implementing an earlier code that I wrote in pure javascript and konva.

0reactions
Rakotoarisoacommented, Aug 28, 2019

Okay. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add layers to maps (Map Viewer Classic) - ArcGIS Online
To get started adding layers, sign in to the site, open Map Viewer Classic, and click the Add button. You can search for...
Read more >
Using layers with your Lambda function - AWS Documentation
Accessing layer content from your function​​ Each Lambda runtime adds specific /opt directory folders to the PATH variable. Your function code can access...
Read more >
Experience Builder - access pop-up for layers add...
I notice that pop-ups for the layers added to the map through this widget cannot be accessed. Could anyone help me figure out...
Read more >
Accessing layers - Sketchbook
From the menubar, select Window > Layer Editor. Accessing layers in Sketchbook for mobile devices. If you're on a tablet, the Layer Editor...
Read more >
Accessing layer's visibility presets? - GIS Stack Exchange
You can access the visibilityPresetCollection through the project instance: QgsProject.instance().visibilityPresetCollection().
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