Lighthouse-io / react-visjs-timeline

React component for the vis.js timeline module
MIT License
210 stars 91 forks source link

Setting state onSelect #104

Open larrywal opened 4 years ago

larrywal commented 4 years ago

I'm using react-visjs-timeline as a react component in a page I have. I have a state setter function (created using UseState react hook).

In my onSelect handler I call the state setter function - but that triggers a redraw of the timeline and the selection in the timeline disappears.

How can I set some state based on the selected item in the timeline without losing the item from being selected? Here's my selection handler. The setSelectedCue is the function that sets the state and triggers the selection to be lost.

  function onSelectHandler ({items, event}) {
    if (items.length === 1) 
    {
      const cueData = this.itemSet.items[items[0]].data;
      const cueObj = cueData.itemType === "FIREWORK" ? 
                      show.fireworkCues.filter(cue => cue._id === cueData.itemID) : 
                      show.lightCues.filter(cue => cue._id === cueData.itemID);
      setSelectedCue({cueType: cueData.itemType, cueObj: cueObj});
    }  
  }
azeghers commented 1 year ago

@larrywal Hi, did you ever find a solution to this problem?