in Education by
I'm importing Popup from react-leaflet import { Marker, Map, Popup, TileLayer, ZoomControl, GeoJSON, ScaleControl} from 'react-leaflet' and trying to extend it class NewPopup extends Popup { onPopupOpen = ({ popup }: { popup: LeafletElement }) => { if (popup === this.leafletElement) { console.log("Here open"); this.onOpen() } } onPopupClose = ({ popup }: { popup: LeafletElement }) => { if (popup === this.leafletElement) { console.log("Here close"); this.onClose() } } } This compiles fine, but when I run it in the browser I get the error "Super expression must either be null or a function, not object" When I console.log the Popup object it looks like this {$$typeof: Symbol(react.forward_ref), render: ƒ, apply: ƒ, bind: ƒ, call: ƒ, …} Rather than a React component. Do I need to import it differently? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This thread discusses why the following error occurs: Super expression must either be null or a function, not object The short answer is: Popup component is not supported to be extended via inheritance in react-leaflet library. In fact even React official documentation encourages 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. Having said that, the following example demonstrates how to customize Popup component: (it will print a message into console once the popup is closed or opened) class MyPopup extends Component { componentDidMount() { const { map } = this.props.leaflet; //get map instance map.on("popupopen", e => { console.log(e.popup); console.log("Popup opened") }); map.on("popupclose", e => { console.log(e.popup); console.log("Popup closed") }); } render() { return ; } } MyPopup component needs to be wrapped with withLeaflet HOC in order to pass Leaflet context Demo

Related questions

0 votes
    This is part of the component : import MyComp from '../../lib/MyComp' const Data = ( { data } ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    This is part of the component : import MyComp from '../../lib/MyComp' const Data = ( { data } ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have a REACTSjs application and am trying to solve a problem with localization. I receive some text from ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm trying to use the sensor's API with react and I can't seen to be able to make it work ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I'm trying to use the sensor's API with react and I can't seen to be able to make it work ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    I've created a getSpectrum method using the getByteFrequencyData method on the Web Audio API's Analyser Node ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    I have a custom input validation component that I use in a form. Something like 15 instances of this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have the following code: let pa = 0; let pw = 0; let pc = 0; let pi = 0; let ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    I have the following code: let pa = 0; let pw = 0; let pc = 0; let pi = 0; let ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am using this codepen https://codepen.io/anon/pen/jJXmpZ but I am struggling to implement a new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I am using this codepen https://codepen.io/anon/pen/jJXmpZ but I am struggling to implement a new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have the following code: let pa = 0; let pw = 0; let pc = 0; let pi = 0; let ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I created an list. When you select each , there will be active classes each. Now, my goal is how ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have function of "endgame" and here's how the function goes function endgame() { setScreen("scorescreen" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    I have created a partial view, the element in the partial view looks like this (Razor Code): @Html ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
...