react-leaflet icon indicating copy to clipboard operation
react-leaflet copied to clipboard

Dynamic Button with onClick in Popup

Open 1Map opened this issue 2 years ago • 1 comments

How can I put a dynamic button in my Popup, when clicked it should fire a react function?

Something like (where I have someCustomReactFunction):

onEachFeature: (feature = {}, layer) => {
  const popup = L.popup();

  const html = `
    <div class="user-popup">
      <button onClick=${someCustomReactFunction}>View</button>
    </div>
  `;

  popup.setContent(html)

  layer.bindPopup(popup);
}

1Map avatar Jan 13 '23 13:01 1Map

onClick={someCustomReactFunction} is how you do it. If I understood the question.

maxymapp avatar Mar 05 '23 06:03 maxymapp