Super expression must either be null or a function (Custom Marker)
up vote
2
down vote
favorite
I'm creating an application where the user can add markers to specific locations on the map just by clicking on the map itself. To this end, I'm using react-leaflet to generate the map and its functionalities. This works perfectly, but I want the popup associated with the marker to be open on creation, and I can't seem to achieve that.
I tried to follow this answer to get this functionality, and import the extended marker to my map. But alas, the following error appears:
Super expression must either be null or a function
at _inherits (Marker.js:21)
at eval (Marker.js:30)
at eval (Marker.js?6e37:11)
at Module../src/utils/components/Marker.js (main.js:11547)
This bothers me a lot, mainly because I can't seem to find a specific answer regarding this error when extending the marker class. Here's my extended marker implementation (couldn't be simpler):
import { Marker } from 'react-leaflet';
class ExtendedMarker extends Marker {
componentDidMount() {
// Call the Marker class componentDidMount (to make sure everything behaves as normal)
super.componentDidMount();
// Access the marker element and open the popup.
this.leafletElement.openPopup();
}
}
export default ExtendedMarker;
And this is where I import it:
import ExtendedMarker from '../../../utils/components/Marker';
...
createMarker = (key, lat, lng) => {
const _lat = round(lat, this.DECIMAL_PLACES);
const _lng = round(lng, this.DECIMAL_PLACES);
return (
<ExtendedMarker key={key} id={key} position={[_lat, _lng]}>
<Popup className={`${styles.popup}`}>
<Form>
...
</Form>
</Popup>
</ExtendedMarker>
)
}
Here are the versions I'm using:
"react-leaflet": "^2.1.2",
"react": "^16.6.1"
Any tips?
Thanks,
Gil
javascript reactjs react-leaflet
add a comment |
up vote
2
down vote
favorite
I'm creating an application where the user can add markers to specific locations on the map just by clicking on the map itself. To this end, I'm using react-leaflet to generate the map and its functionalities. This works perfectly, but I want the popup associated with the marker to be open on creation, and I can't seem to achieve that.
I tried to follow this answer to get this functionality, and import the extended marker to my map. But alas, the following error appears:
Super expression must either be null or a function
at _inherits (Marker.js:21)
at eval (Marker.js:30)
at eval (Marker.js?6e37:11)
at Module../src/utils/components/Marker.js (main.js:11547)
This bothers me a lot, mainly because I can't seem to find a specific answer regarding this error when extending the marker class. Here's my extended marker implementation (couldn't be simpler):
import { Marker } from 'react-leaflet';
class ExtendedMarker extends Marker {
componentDidMount() {
// Call the Marker class componentDidMount (to make sure everything behaves as normal)
super.componentDidMount();
// Access the marker element and open the popup.
this.leafletElement.openPopup();
}
}
export default ExtendedMarker;
And this is where I import it:
import ExtendedMarker from '../../../utils/components/Marker';
...
createMarker = (key, lat, lng) => {
const _lat = round(lat, this.DECIMAL_PLACES);
const _lng = round(lng, this.DECIMAL_PLACES);
return (
<ExtendedMarker key={key} id={key} position={[_lat, _lng]}>
<Popup className={`${styles.popup}`}>
<Form>
...
</Form>
</Popup>
</ExtendedMarker>
)
}
Here are the versions I'm using:
"react-leaflet": "^2.1.2",
"react": "^16.6.1"
Any tips?
Thanks,
Gil
javascript reactjs react-leaflet
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm creating an application where the user can add markers to specific locations on the map just by clicking on the map itself. To this end, I'm using react-leaflet to generate the map and its functionalities. This works perfectly, but I want the popup associated with the marker to be open on creation, and I can't seem to achieve that.
I tried to follow this answer to get this functionality, and import the extended marker to my map. But alas, the following error appears:
Super expression must either be null or a function
at _inherits (Marker.js:21)
at eval (Marker.js:30)
at eval (Marker.js?6e37:11)
at Module../src/utils/components/Marker.js (main.js:11547)
This bothers me a lot, mainly because I can't seem to find a specific answer regarding this error when extending the marker class. Here's my extended marker implementation (couldn't be simpler):
import { Marker } from 'react-leaflet';
class ExtendedMarker extends Marker {
componentDidMount() {
// Call the Marker class componentDidMount (to make sure everything behaves as normal)
super.componentDidMount();
// Access the marker element and open the popup.
this.leafletElement.openPopup();
}
}
export default ExtendedMarker;
And this is where I import it:
import ExtendedMarker from '../../../utils/components/Marker';
...
createMarker = (key, lat, lng) => {
const _lat = round(lat, this.DECIMAL_PLACES);
const _lng = round(lng, this.DECIMAL_PLACES);
return (
<ExtendedMarker key={key} id={key} position={[_lat, _lng]}>
<Popup className={`${styles.popup}`}>
<Form>
...
</Form>
</Popup>
</ExtendedMarker>
)
}
Here are the versions I'm using:
"react-leaflet": "^2.1.2",
"react": "^16.6.1"
Any tips?
Thanks,
Gil
javascript reactjs react-leaflet
I'm creating an application where the user can add markers to specific locations on the map just by clicking on the map itself. To this end, I'm using react-leaflet to generate the map and its functionalities. This works perfectly, but I want the popup associated with the marker to be open on creation, and I can't seem to achieve that.
I tried to follow this answer to get this functionality, and import the extended marker to my map. But alas, the following error appears:
Super expression must either be null or a function
at _inherits (Marker.js:21)
at eval (Marker.js:30)
at eval (Marker.js?6e37:11)
at Module../src/utils/components/Marker.js (main.js:11547)
This bothers me a lot, mainly because I can't seem to find a specific answer regarding this error when extending the marker class. Here's my extended marker implementation (couldn't be simpler):
import { Marker } from 'react-leaflet';
class ExtendedMarker extends Marker {
componentDidMount() {
// Call the Marker class componentDidMount (to make sure everything behaves as normal)
super.componentDidMount();
// Access the marker element and open the popup.
this.leafletElement.openPopup();
}
}
export default ExtendedMarker;
And this is where I import it:
import ExtendedMarker from '../../../utils/components/Marker';
...
createMarker = (key, lat, lng) => {
const _lat = round(lat, this.DECIMAL_PLACES);
const _lng = round(lng, this.DECIMAL_PLACES);
return (
<ExtendedMarker key={key} id={key} position={[_lat, _lng]}>
<Popup className={`${styles.popup}`}>
<Form>
...
</Form>
</Popup>
</ExtendedMarker>
)
}
Here are the versions I'm using:
"react-leaflet": "^2.1.2",
"react": "^16.6.1"
Any tips?
Thanks,
Gil
javascript reactjs react-leaflet
javascript reactjs react-leaflet
asked Nov 20 at 16:54
gilneto8
455
455
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Since React official documentation suggests to prefer composition over inheritance:
At Facebook, we use React in thousands of components, and we haven’t
found any use cases where we would recommend creating component
inheritance hierarchies.
Props and composition give you all the flexibility you need to
customize a component’s look and behavior in an explicit and safe way.
Remember that components may accept arbitrary props, including
primitive values, React elements, or functions.
i would suggest the following marker component which demonstrates how to open a popup on marker creation:
const ExtendedMarker = props => {
const openPopup = marker => {
if (marker) marker.leafletElement.openPopup();
};
return (
<Marker ref={el => openPopup(el)} {...props}/>
);
};
A callback function is used to access Leaflet Marker
via marker.leafletElement
Here is a demo for your reference
1
That made sense, I was looking at this from another point of view. It worked, thank you so much.
– gilneto8
Nov 26 at 10:52
1
This is a great answer in that it points you in the right direction. It does not explain why you get that error though. That error happens because the author ofreact-leaflet
published v2 of his library and completely changed the way extending components works for most components. For a more in depth read on why exactly you get that error check out this github issue: github.com/PaulLeCam/react-leaflet/issues/506
– jbccollins
Nov 26 at 14:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397849%2fsuper-expression-must-either-be-null-or-a-function-custom-marker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Since React official documentation suggests to prefer composition over inheritance:
At Facebook, we use React in thousands of components, and we haven’t
found any use cases where we would recommend creating component
inheritance hierarchies.
Props and composition give you all the flexibility you need to
customize a component’s look and behavior in an explicit and safe way.
Remember that components may accept arbitrary props, including
primitive values, React elements, or functions.
i would suggest the following marker component which demonstrates how to open a popup on marker creation:
const ExtendedMarker = props => {
const openPopup = marker => {
if (marker) marker.leafletElement.openPopup();
};
return (
<Marker ref={el => openPopup(el)} {...props}/>
);
};
A callback function is used to access Leaflet Marker
via marker.leafletElement
Here is a demo for your reference
1
That made sense, I was looking at this from another point of view. It worked, thank you so much.
– gilneto8
Nov 26 at 10:52
1
This is a great answer in that it points you in the right direction. It does not explain why you get that error though. That error happens because the author ofreact-leaflet
published v2 of his library and completely changed the way extending components works for most components. For a more in depth read on why exactly you get that error check out this github issue: github.com/PaulLeCam/react-leaflet/issues/506
– jbccollins
Nov 26 at 14:25
add a comment |
up vote
1
down vote
accepted
Since React official documentation suggests to prefer composition over inheritance:
At Facebook, we use React in thousands of components, and we haven’t
found any use cases where we would recommend creating component
inheritance hierarchies.
Props and composition give you all the flexibility you need to
customize a component’s look and behavior in an explicit and safe way.
Remember that components may accept arbitrary props, including
primitive values, React elements, or functions.
i would suggest the following marker component which demonstrates how to open a popup on marker creation:
const ExtendedMarker = props => {
const openPopup = marker => {
if (marker) marker.leafletElement.openPopup();
};
return (
<Marker ref={el => openPopup(el)} {...props}/>
);
};
A callback function is used to access Leaflet Marker
via marker.leafletElement
Here is a demo for your reference
1
That made sense, I was looking at this from another point of view. It worked, thank you so much.
– gilneto8
Nov 26 at 10:52
1
This is a great answer in that it points you in the right direction. It does not explain why you get that error though. That error happens because the author ofreact-leaflet
published v2 of his library and completely changed the way extending components works for most components. For a more in depth read on why exactly you get that error check out this github issue: github.com/PaulLeCam/react-leaflet/issues/506
– jbccollins
Nov 26 at 14:25
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Since React official documentation suggests to prefer composition over inheritance:
At Facebook, we use React in thousands of components, and we haven’t
found any use cases where we would recommend creating component
inheritance hierarchies.
Props and composition give you all the flexibility you need to
customize a component’s look and behavior in an explicit and safe way.
Remember that components may accept arbitrary props, including
primitive values, React elements, or functions.
i would suggest the following marker component which demonstrates how to open a popup on marker creation:
const ExtendedMarker = props => {
const openPopup = marker => {
if (marker) marker.leafletElement.openPopup();
};
return (
<Marker ref={el => openPopup(el)} {...props}/>
);
};
A callback function is used to access Leaflet Marker
via marker.leafletElement
Here is a demo for your reference
Since React official documentation suggests to prefer composition over inheritance:
At Facebook, we use React in thousands of components, and we haven’t
found any use cases where we would recommend creating component
inheritance hierarchies.
Props and composition give you all the flexibility you need to
customize a component’s look and behavior in an explicit and safe way.
Remember that components may accept arbitrary props, including
primitive values, React elements, or functions.
i would suggest the following marker component which demonstrates how to open a popup on marker creation:
const ExtendedMarker = props => {
const openPopup = marker => {
if (marker) marker.leafletElement.openPopup();
};
return (
<Marker ref={el => openPopup(el)} {...props}/>
);
};
A callback function is used to access Leaflet Marker
via marker.leafletElement
Here is a demo for your reference
edited Nov 26 at 9:04
answered Nov 25 at 20:39
Vadim Gremyachev
34.2k669110
34.2k669110
1
That made sense, I was looking at this from another point of view. It worked, thank you so much.
– gilneto8
Nov 26 at 10:52
1
This is a great answer in that it points you in the right direction. It does not explain why you get that error though. That error happens because the author ofreact-leaflet
published v2 of his library and completely changed the way extending components works for most components. For a more in depth read on why exactly you get that error check out this github issue: github.com/PaulLeCam/react-leaflet/issues/506
– jbccollins
Nov 26 at 14:25
add a comment |
1
That made sense, I was looking at this from another point of view. It worked, thank you so much.
– gilneto8
Nov 26 at 10:52
1
This is a great answer in that it points you in the right direction. It does not explain why you get that error though. That error happens because the author ofreact-leaflet
published v2 of his library and completely changed the way extending components works for most components. For a more in depth read on why exactly you get that error check out this github issue: github.com/PaulLeCam/react-leaflet/issues/506
– jbccollins
Nov 26 at 14:25
1
1
That made sense, I was looking at this from another point of view. It worked, thank you so much.
– gilneto8
Nov 26 at 10:52
That made sense, I was looking at this from another point of view. It worked, thank you so much.
– gilneto8
Nov 26 at 10:52
1
1
This is a great answer in that it points you in the right direction. It does not explain why you get that error though. That error happens because the author of
react-leaflet
published v2 of his library and completely changed the way extending components works for most components. For a more in depth read on why exactly you get that error check out this github issue: github.com/PaulLeCam/react-leaflet/issues/506– jbccollins
Nov 26 at 14:25
This is a great answer in that it points you in the right direction. It does not explain why you get that error though. That error happens because the author of
react-leaflet
published v2 of his library and completely changed the way extending components works for most components. For a more in depth read on why exactly you get that error check out this github issue: github.com/PaulLeCam/react-leaflet/issues/506– jbccollins
Nov 26 at 14:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397849%2fsuper-expression-must-either-be-null-or-a-function-custom-marker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown