react-timeline-editor
react-timeline-editor copied to clipboard
Anyone facing issue when updating the data outside the timeline context
I am working on a task in which i have to update the data from outside the timeline
when this editor data is changed outside then it shows error Invalid offset NaN specified
const editorData = useMemo(() => updatedTracks(timeline.data), [timeline.data]);
import { useMemo } from 'react';
import { Timeline } from '@xzdarcy/react-timeline-editor';
import { TimelineControls } from './TimelineControls/TimelineControls';
import { startLeft, useTimeLine } from '../TimelineContext/TimelineContext';
import { updatedTracks } from './fields';
import { AudioRender } from './CustomElements/AudioRender';
import { VideoRender } from './CustomElements/RenderVideo';
import './Timeline.less';
const TimelineComponent = () => {
const { timelineRef, selectedSegment, scaleWidth, ...timeline } = useTimeLine();
const editorData = useMemo(() => updatedTracks(timeline.data), [timeline.data]);
const mockEffect = {
effect0: {
id: 'effect0',
name: '效果0',
},
};
return (
<div style={{ height: '150px', position: 'relative', width: '100%' }}>
<TimelineControls />
<Timeline
ref={timelineRef as any}
editorData={editorData}
autoScroll={true}
effects={mockEffect}
onChange={() => {}}
onClickAction={(ev, a) => timeline.setSelectedSegment(a.action)}
scaleSplitCount={10}
scaleWidth={scaleWidth}
startLeft={startLeft}
getActionRender={(action, row) => {
if (row.id === '1') {
return <VideoRender action={action} row={row} />;
}
if (row.id === '2') {
return <AudioRender action={action} row={row} />;
}
}}
style={{ width: '100%' }}
/>
</div>
);
};
export default TimelineComponent;