Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
msimonian77 opened this issue Jul 27, 2020 · 2 comments

Comments

@msimonian77
Copy link

msimonian77 commented Jul 27, 2020

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
Copy link
Author

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

@razbensimon
Copy link
Owner

razbensimon commented Aug 23, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants