rcdexta / react-event-timeline

A responsive event timeline in React.js
https://rcdexta.com/react-event-timeline
MIT License
536 stars 56 forks source link

how to create TimelineEvents dynamically #3

Closed nandinias closed 7 years ago

nandinias commented 7 years ago

m trying to create events dynamically but m getting exception 'Component's children should not be' mutated.

rcdexta commented 7 years ago

@nandinias Can you share the code and more details about what exactly you mean by dynamic events?

nandinias commented 7 years ago

Thank u for replaying.I have solved the problem.my question was I wanted to create event timeline inside timeline.timeline events are not fixed it should create events based on my response data. But now I have doubt is it possible to sort the display of timeline events.

On 29 Dec 2016 9:40 pm, "RC" notifications@github.com wrote:

@nandinias https://github.com/nandinias Can you share the code and more details about what exactly you mean by dynamic events?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rcdexta/react-event-timeline/issues/3#issuecomment-269652298, or mute the thread https://github.com/notifications/unsubscribe-auth/AXrRIlBrCZaqWy4GpkkqL_w6zsVTvZm8ks5rM9t-gaJpZM4LXjLe .

rcdexta commented 7 years ago

let's assume your response data is a json array of the following form. I have tried to give an example below:

let data = [{id: 3, title: 'Event3', createdAt: '12 am', label: 'blah'}, 
                 {id: 2, title: 'Event2', createdAt: '10 pm', label: 'foo'},
                 {id: 1, title: 'Event1', createdAt: '11 am', label: 'bar'}]

 <Timeline>
       {
               data.sort((a,b) => a.id - b.id).map((elt) =>  {
                      return <TimelineEvent title={elt.title} key={elt.id} createdAt={elt.createdAt}>
                                            {elt.label}
                                 </TimelineEvent>
               })       
       } 
</Timeline>

The data is sorted by id field and then the TimelineEvent component is generated by iterating over the data array. Hope this helps!

rcdexta commented 7 years ago

Am closing this issue as this sounds to be an informational thread to me..