Skip to content

Setting state onSelectΒ #104

@larrywal

Description

@larrywal

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});
    }  
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions