react-vis-timeline icon indicating copy to clipboard operation
react-vis-timeline copied to clipboard

There is no way to update the items as it only takes in the initialItems

Open msimonian77 opened this issue 5 years ago • 2 comments

Overview

We dynamically change the items but here the items are initial only? Was that intentional?

Package versions

react-vis-timeline: 2.0.3 vis version: 4.21.0

Steps to reproduce

Add step by step guide to reproduce issue

  1. Creating the timeline sending in initialItems and initialGroups
  2. Items were updated but the timeline stays the same

Code Snippet

           <Timeline
                options={timelineOptions}
                ref={timelineRef}
                initialItems={timelineItems}
                initialGroups={updatedGroups}
                rangechangeHandler={rangeChangeHandler}
            />

Related issues

Any issue which is related to this issue

  • e.g. issue 123

Screenshots (if appropriate)

msimonian77 avatar Jul 27 '20 23:07 msimonian77

what i did was instead of adding the items in initialItems I added them in a useEffect: useEffect( () => { if (timelineRef.current.timeline) { timelineRef.current.timeline.setItems(timelineItems); } }, [timelineItems] );

msimonian77 avatar Jul 30 '20 00:07 msimonian77

what i did was instead of adding the items in initialItems I added them in a useEffect: useEffect( () => { if (timelineRef.current.timeline) { timelineRef.current.timeline.setItems(timelineItems); } }, [timelineItems] );

Yes, your mehod is correct for changing the items. initialItems is exists for more like static situations, when you have all data before and just want to display it once. I know it can be confusing - two ways for passing data. So I works on next version, which uses only react props, but also good at performance by using vis's native api.

razbensimon avatar Aug 23 '20 21:08 razbensimon