Lighthouse-io / react-visjs-timeline

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

Event handlers not updated #53

Open udalrich opened 6 years ago

udalrich commented 6 years ago

Overview

Handlers are only initialized in componentDidMount, so it does handler changes based on state changes do not result in an updated hander.

Package versions

react-visas-timeline: 1.4.0 vis version: 4.21.0

Steps to reproduce

Create a timeline with a clickHandler that depends on the state. Change that part of the state. Click the item.

The original handler is called.

Code Snippet

const MyComponent = ({items}}} => (
  <VisTimeline items={items}
            clickHandler={() => console.log('click', items)
    />);

Add additional elements to so that items changes from its initial value. After items is updated, clicking on an item prints the original value of items.

Related issues

Screenshots (if appropriate)

larrywal commented 4 years ago

Any updates here? This is really a pain for me - I've tried to workaround it where possible....

suulola commented 3 years ago

@larrywal @udalrich how did you fix this in your codebase eventually

udalrich commented 3 years ago

I feel like I made a local copy and edited VisTimeline to recalculate the handler. But I'm not able to find that at the moment, so I can't see exactly what I did. If my memory is correct, it wasn't a complicated change.

suulola commented 3 years ago

Thanks @udalrich. Found a way around it by re-rendering the component every time the item changes. Works for my use case. Appreciated